Absolute beginner c++ If statment

Hello, could you please look at my code. It suppose to make the user type in a number, if the number is over 16 it will print out something, and if the number is under 16 something else will be printed out. At the moment it seems to print out both lines no matter what.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int main()
{

   int x;
   int y;

   cout <<"hello my friend, what's your age?" <<endl;
   cin  >> x;

   if (x <= 16){

   cout << x <<" your a young one huh" <<endl;
   }

   if (y >=16){

   cout << "get out of here you grumpy old one."<< endl;
   }


    return 0;
}



Thanks alot of whatever help you guys can give me :)
total new to this.
Last edited on
if (y >=16){

What value does y have at this point? When did it get set?
haha, forgot so set a value for y. Do you have any tips how i can make a value for y?
Why does the variable y exist? What data is it meant to hold?
That's a good question, thx for helping me you just got me to understand that i only needed the X, so i just removed Y from the code. Works perfectly :)
Does it still work perfectly if your age is 16?

The way it is coded, both statements are true if x is 16. Try this.

1
2
3
4
5
6
if (x <= 16){
	   cout << x <<" your a young one huh" <<endl;
   }
   else {
	   cout << "get out of here you grumpy old one."<< endl;
   }
Topic archived. No new replies allowed.