- 1
if the age is greater than 18
4 Respostas
+ 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";
}
+ 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.
0
int age;
if(age>18)
{
//statements
}
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