+ 1

Can I get some help with my simple c++ program?

Hello, reader! So I am trying to write a simple c++ code about age. Basically, the user inputs their age, and the code will print out that they are an adult if the age is above 18, else tell them that they are not an adult. Here is the code below. I hope someone can figure out what's wrong. #include <iostream> using namespace std; int main () { int age; cout << " insert age" << endl; cin >> age; if (age > 18); cout << " you are an adult!" << endl; else; cout << "you are not an adult!" << endl; return 0; }

4th Apr 2019, 1:46 AM
Alfred Diana
Alfred Diana - avatar
1 Answer
+ 4
Just remove the semicolons after if statement and else statement. if (age >= 18) cout << " you are an adult!" << endl; else cout << "you are not an adult!" << endl;
4th Apr 2019, 1:53 AM
Fermi
Fermi - avatar