when i run this code and enter 5 5 5.
why doesnt the code give any maximum number in this code?
#include<iostream>
using namespace std;
int main()
{int x1,x2,x3;
cin>>x1>>x2>>x3;
if(x1>x2)
if(x1>x3)
cout<<x1;
else
cout<<x3;
if(x2>x3)
if(x2>x1)
cout<<x2;
else
cout<<x3;
}
Last edited on
You have to use parenthesis like so:
1 2 3 4 5 6 7
|
if(x1>x2)
{
if(x1>x3)
cout<<x1;
}
else
cout<<x3;
|
Otherwise it's a much better idea to put it all in one
if
1 2 3 4
|
if (x1 > x2 && x1 > x3)
cout << x1;
else
cout << x3;
|
The Clang compilers gives off a warning about this.
Last edited on