help with the program; How to find the largest integers and equal integers

I m having hard time to fix my code.
I need to find the largest integers among three integers and also
need to display when all three integers are equal.
I didn't have an error with my code, but when all numbers are equal,
it says third numbers are the largest and its equal.
I need to fix it.


#include<iostream>
using namespace std;
int main()
{
int num1, num2, num3;
cout << " Enter value for first number";
cin >> num1;

cout << " Enter value for second number";
cin >> num2;

cout << " Enter value for third number";
cin >> num3;
if (num1>num2&&num1>num3)
{
cout << " First number is greatest:" << endl << "whick is= " << num1;
}
else if (num2>num1&&num2>num3)
{
cout << " Second number is greatest" << endl << "whick is= " << num2;
}
else
{
cout << " Third number is greatest" << endl << "whick is= " << num3;
}
if (num1=num2=num3)
{
cout << " All numbers are equal" << endl << "which is=" << num1, num2, num3;
}

return 0;
}




Well if all the numbers are equal ehy would you want to show the value of num1, num2, and num3. Since they are all equal just cout 1 of them to show what the number is
And even if you did want to output all them it would be
num1 << num2 << num3;

Instead of num1, num2, num3
closed account (j3Rz8vqX)
if (num1=num2=num3)//Assignment operator
What you want is equality operation ==

And it must be done:
1
2
3
4
5
else if(num3>num1 && num3>num2)
{
    cout << " Third number is greatest" << endl << "whick is= " << num3;
}
else if (num1==num2 && num2==num3)


And what football52 said: (above post)
Last edited on
Topic archived. No new replies allowed.