When I run this code, it always tells me the largest number is the first one inputed. Why is that?
I know there is a more efficient way to do this with an array, but my teacher doesn't want us to for this lab.
Thank you!
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
int num1, num2, num3, largest;
cout << "Please enter three numbers, separated by commas." << endl;
cin >> num1, num2, num3 ;
if ((num1>num2) and (num1>num3))
{
largest=num1;
}
elseif ((num2>num1) and (num2>num3))
{
largest=num2;
}
elseif ((num3>num1) and (num3>num2))
{
largest=num3;
}
cout << "Thank you. The largest of the three is " << largest << endl;
return 0;
}