#include <iostream>
#include <cstdio>
#include <cstdlib>
usingnamespace std;
int main()
{
int a;
int b;
cout << " Enter two numbers " ;
cin>>a;
cin>>b;
if (a>b)
{
cout<<"The number "<<a<<" is larger than "<<b<<endl;
}
elseif (a<b)
{
cout <<"The number "<<a<<" is smaller than "<<b<<endl;
}
elseif (a==b)
{
cout <<"The number "<<a<<" is the same as "<<b<<endl;
}
else();
{
cout<<"You didn't enter a number"<<endl;
}
system("PAUSE");
return 0;
}
The else statement has no any condition. Moreover if you checked a < b and a > b then it is obvious that there is only one variant a == b. So you can rewritte your if-else statements the following way
1 2 3 4 5 6 7 8 9 10 11 12
if (a>b)
{
cout<<"The number "<<a<<" is larger than "<<b<<endl;
}
elseif (a<b)
{
cout <<"The number "<<a<<" is smaller than "<<b<<endl;
}
else
{
cout <<"The number "<<a<<" is the same as "<<b<<endl;
}
Yeah but what i want is just more control on what happens i guess, like say they enter an "H" i want it to say they entered a LETTER or tell them "H is not a number"
I am rather new to c ++. What do you mean by that? I want it to compare the integer values of a and b but if its a letter or something of the sort, tell them its invalid.