I am having a problem with my if statement as on the tutorial in the "Statements and flow control" section it has this code:
1 2 3 4
if (x == 100)
cout << "x is 100";
else
cout << "x is not 100";
But when I put that in i get an error with the == part saying it's not a operator. If I am doing anything wrong, Please reply to me as soon as possible as I can trying to learn C++ but not getting anywhere with this bug.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string x;
cout << "Enter number here please: ";
cin >> x;
if (x == 100)
cout << "your number is 100" << endl;
else
cout << "Your number is not 100. It is " << x << endl;
return 0;
}
I have tried using getline(cin, x) instead of just cin x; but still getting the same error.
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int x;
cout << "Enter number here please: ";
cin >> x;
if (x==100)
cout << "your number is 100" << endl;
else
cout << "Your number is not 100. It is " << x << endl;
return 0;
}