help with this..i confuse

MY COMMAND(WHERE THE FIRST VALUE IS 25,25,12):
#include "stdafx.h"
#include<iostream>
using namespace std;

void main()
{int Data_1,Data_2,Data_3;
cout<<"key in first number:";
cin>>Data_1;
cout<<"key in second number:";
cin>>Data_2;
cout<<"key in third number:";
cin>>Data_3;
if((Data_1>Data_2)&&(Data_1>Data_3))
{
cout<<Data_1<<": is the biggest\n";
}
else if((Data_2>Data_1)&&(Data_2>Data_3))
{
cout<<Data_2<<": is the biggest\n";
}
else
{
cout<<Data_3<<": is the biggest\n";
}
}


MY OUTPUT:
key in first number:25
key in second number:25
key in third number:12
12: is the biggest
Press any key to continue . . .


WHY I GET 12 INSTEAD OF 25?????????????????
Last edited on
Try to see the numbers in your code instead of the variables and you'll see why you get the result you do..

1
2
3
if( 25 > 25 && 25 > 12 ) false
else if( 25 > 25 && 25 > 12 ) false
else cout << Data_3 which is 12
WHY I GET 12 INSTEAD OF 25?????????????????

Because your logic is wrong.

if ((Data_1 > Data_2) && (Data_1 > Data_3))

Let's consider what that looks like when the variables have the values you entered:

if ((25 > 25) && (25 > 12))

25 > 25 is false, so the if statement evaluates to false. Therefore, the statement governed by the first if statement will not execute. Data_1 is not the biggest.

else if((Data_2>Data_1)&&(Data_2>Data_3))
turns into:
else if((25 > 25) && (25 > 12))

25 > 25 is false, so the if statement evaluates to false. Data_2 is not the biggest.
There's only one option left, and that's 12.
Thanks..I not notice it..
Topic archived. No new replies allowed.