I'm trying the if and else statement but it's not working

so I've been trying the if and else statement and I've tried to do a basic console program with it but it isn't working and I can't understand why.


#include <cmath>
#include <iostream>

int main()
{
using namespace std;

int answer;

cout << " enter 1" << endl;
cin << answer;

if ( answer == 1)
{
cout << "thank you" << endl;
}

else
{
cout << " you had one job" << endl;
}


system("PAUSE");
return 0;
}
Last edited on
|9|error: no match for 'operator<<' in 'std::cin << answer'|

So, cin << answer; should be cin >> answer;
Hi,

On line 11:

cin >> answer;

Please always use code tags:

http://www.cplusplus.com/articles/z13hAqkS/
What naaissus said is the problem with your code. think of the operators << and >> as arrows pointing in your code. << points towards cout which means it is pointing "outwards" toward the screen. >> is "inwards" toward the computer.

I am a fresh programmer but I do know that using namespace std; should be outside of your program. using that in your main only will keep it in main's scope and will cause problems when you reach function, structures, classes, etc.
Last edited on
Better yet, don't have using namespace std; at all. Google to see why, and what to do instead :+)
Last edited on
Topic archived. No new replies allowed.