#include <iostream>
int main()
{
usingnamespace std;
int age;
char name [5];
cout << "Hi, whats your name? \n" ;
cin >> name ;
cout << " So " << name << " how old are you? \n";
cin >> age;
if (age > 20)
cout << " Great!\n";
else
cout << " too bad your too young \n ";
return 0;
}
You can see that the if statement recognises int variables and can decipher whether or not the input from cin is greater than 20.
Is there a way you can use an if statement to, for example decipher between the word yes or no. Or distinguish between 2 names?
It's being written in Microsoft Visual C++ 2008 if that helps