Hey guys! I got a problem right here...
When I run the program and choose an age under 18 in I'll get ""Hey kid, go to bed!"" which is good :p
But when I test and pick an age over 18, i get both the
"Oh man you're old!"
AND
"Hey kid, go to bed!"
What have I done wrong and what should I do to solve this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include "stdafx.h"
#include <iostream>
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
int age;
cout << "Hey, how old are you?" << endl;
cin >> age;
if (age > 18)
cout << "Oh man you're old!\n";
else (age < 18);
cout << "Hey kid, go to bed!\n"
cin.get();
cin.get();
return 0;
}
|
(I'm a newbie as you can see)
Thanks!
Last edited on
I can't believe this compiles..
else (age < 18);
cout << "Hey kid, go to bed!\n"
is bad syntax.. you even forgot the ';' after cout
use either
else {
cout << "Hey kid, go to bed!\n" }
or
else if (age < 18) { ..
@Peter87 Jinx.. 1.. 2.. 3..
ah alright! It's working now ;p
Thanks guys!
Last edited on