+ 2

Why wont my code work

#include <iostream> using namespace std; int main(){ int age; cout << "Please enter age. \n"; cin >> age >> endl; if (age <= 17){ cout << "sorry you must me 18+ \n"; } if (age >= 18){ cout << "welcome"; } return 0; }

29th Nov 2016, 8:15 PM
Hunter Davis
Hunter Davis - avatar
7 Respuestas
+ 9
Try deleting the endl in cin. I think that's the error
29th Nov 2016, 9:08 PM
Filip
Filip - avatar
+ 7
Yeah, the endl is the problem, you can't end the line when you are inputing stuff, does that make sense to you?
29th Nov 2016, 9:16 PM
Filip
Filip - avatar
+ 6
@HunterDavis No problem man :)
29th Nov 2016, 9:17 PM
Filip
Filip - avatar
+ 3
@fillip removing endl after cin fixed it thanks!
29th Nov 2016, 9:16 PM
Hunter Davis
Hunter Davis - avatar
+ 1
u can use switch case to solve this problem and it is in switch. and by the way you're program is right and it won't work in phones and phone is not capable to run the output
30th Nov 2016, 2:12 PM
Mani Maran
Mani Maran - avatar
0
are you correctly indenting the ifs?
29th Nov 2016, 8:39 PM
Cristi Vlad
Cristi Vlad - avatar
0
i think so
29th Nov 2016, 8:40 PM
Hunter Davis
Hunter Davis - avatar