greater than and less than in if statements

i was trying to make a program that would make the user enter 1, but i don't understand how you use < or > in if statements.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;


int main ()

{
long a;

cout << "enter the number 1 and press enter";
cin >> a;


if (a==1) cout<< "You got it right";
if (a==<1) cout<< "You're a moron, you were supposed to press 5";
if (a==>1) cout<< "You're a moron, you were supposed to press 5";

                                   cin.ignore(LONG_MAX,'\n');
            			           cin.get ();
			           
					
                    return 0;
    }
1
2
if (a==<1) cout<< "You're a moron, you were supposed to press 5";
if (a==>1) cout<< "You're a moron, you were supposed to press 5";


Wait! I thought that he was supposed to press 1.

1
2
3
if (a > 1) 

if (a < 1)


Take a look at this for what you should do when the moron enters something that isn't even a number.
http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.3
Last edited on
I fixed it with the help of this page: http://cplusplus.com/doc/tutorial/control/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;


int main ()

{
long a;

cout << "enter the number 1 and press enter";
cin >> a;


if (a==1) cout<< "You got it right";
if (a<1) cout<< "You're a moron, you were supposed to press 1";
if (a>1) cout<< "You're a moron, you were supposed to press 1";

                                   cin.ignore(LONG_MAX,'\n');
            			           cin.get ();
			           
					
                    return 0;
    }
Topic archived. No new replies allowed.