"Expected ';' before 'cout'

Hi, so i was working in c++ on a little practice program and i keep getting the error
"Expected ';' before 'cout'. someone help please? here's the code so far:

#include <iostream>

using namespace std;

int main()
{
int age;
cout << "Hello. please enter your age.!" << endl;
cin >> age;
if ( age < 20 )
cout << "you are quite young and have a lot to learn" << endl;


else if ( age > 20 ) ( age < 40 )
cout << "you are finally out in the real world. But your still young" << endl;

else if ( age > 40 ) ( age < 60 )
cout << "Your middle age and have enough life xperience to educate the youth. Don't let it go to waste" << endl;

else ( age > 60 ) ( age < 80 )
cout << "Dude, your old. Enough said" << endl;

return 0;
}
Last edited on
#include <iostream>

using namespace std;

int main()
{
int age;
cout << "Hello. please enter your age.!" << endl;
cin >> age;
if ( age < 20 )
cout << "you are quite young and have a lot to learn" << endl;


else if (( age > 20 ) && ( age < 40 ))
cout << "you are finally out in the real world. But your still young" << endl;

else if (( age > 40 ) && ( age < 60 ))
cout << "Your middle age and have enough life xperience to educate the youth. Don't let it go to waste" << endl;

else {(( age > 60 ) && ( age < 80 ));
cout << "Dude, your old. Enough said" << endl;
}
return 0;
}
Dude thank you so much. If you wouldn't mind, could you explain what you did for future reference?
Note your if statements. You forgot to put the ampersands between the two arguments. The way you had it wasn't going to read both arguments.

if ((x == 3) && (y == 4))
means if x is 3 and y is 4

if ((x == 3) || (y == 4))
means if x is 3 or y is 4

Edit: I forgot to note that you also needed those squiggly brackets on your final else statement.
Last edited on
thanks.
Also, another problem is still with your arguments. The way you have it written, if someones age is 40 or 60, nothing is going to happen. Try using <= and >= which is greater than or equal to, and less than or equal to. It will include those numbers.
ah, didn't catch that. i guess i need to be more specific about my math.
On the subject of math, do a little reading on the difference between == and =
They are two totally separate things and will drive you crazy if you misuse them on a program.

= is used for assigning value to something

For example, if you have a value that will change, such as figuring out weekly pay, your code is this:
pay = hours * wage
So pay will adjust according to how you adjust your hours and wages in the program.

== means equal to
So pretend we have a variable called n and you have a line which is
if (n + 50 == 100)
That will mean that if n + 50 equals 100, then everything in your if statement will happen.
btw, to get code formatted like this, use code tags.

i.e. [ code]code here...[/code]
Last edited on
@ecstasyaeternus Thanks, i was slightly confused on that too, but now it makes sense.

@modshop Thanks, will do from now on
Topic archived. No new replies allowed.