- 1

if the age is greater than 18

16th Jul 2016, 5:28 PM
Narayana Ganji
Narayana Ganji - avatar
4 ответов
+ 1
Not entirely sure what your question is, but this would do just fine! #include <iostream> int main() { int age; std::cout << "Enter your age: "; std::cin >> age; if (age < 0) { std::cout << "Cool story\n"; return 0; } if (age >= 18) std::cout << "You are 18 years old or over!\n"; else std::cout << "You are under 18 years old!\n"; }
16th Jul 2016, 6:10 PM
Cohen Creber
Cohen Creber - avatar
+ 1
return 0 from main will end the program. Unless we create some sort of loop, then if the user inputs an age that is less than 0, there will be no output. That return 0 is there for input control, as no one is under 0 years old.
1st Sep 2016, 5:20 PM
Cohen Creber
Cohen Creber - avatar
0
int age; if(age>18) { //statements }
14th Aug 2016, 5:58 AM
Pritam Das
Pritam Das - avatar
0
i just saw the above code, and i have a question Q) why are there further statements after return 0, i thought return 0 gives control back to the user and the program stops
1st Sep 2016, 5:17 PM
Leslie Jason
Leslie Jason - avatar