Click here to Skip to main content
15,903,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include<stdio.h>
int main()
{
  int a,b,c;
  scanf("%d\n%d\n%d\n",&a,&b,&c);
  if(a != b || a != c)
  {
    printf("1");
  }
  else if(b != c)
  {
    printf("1");
  }
  else
  {
    Printf("0");
  }
  return 0;
}


What I have tried:

to input 3 integers if 3 are same print 1 else print 0
Posted
Updated 6-Aug-17 3:51am
v2
Comments
Kornfeld Eliyahu Peter 6-Aug-17 9:32am    
I would advise you to read your conditions out - loud and in human language...

While waiting for a description of the problem in your code, give a try to debugger.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 
v2
Comments
Nelek 7-Aug-17 1:39am    
Give a fish to a hungry man, and he will eat one day.
Give a fishing set and teach him how to use it, and he will eat every day.
Patrice T 7-Aug-17 5:04am    
:)
Currently, your code does this:

  1. If a is not b or a is not c, print 1.
  2. If b is not c, print 1.
  3. If the above conditions are not true, print 0.

This does not sound like what you want; you wanted to print 1 if all values are the same, so you want this:
C++
if (a == b && a == c) // if a is b AND a is c (then b is c, so a and b and c are the same)
{
    printf("1");
}
else // the above conditions is not true; at least one of the three numbers is different
{
    printf("0");
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900