Hello im new to the forums and figured I would sign up to see if anyone could help me with this problem I am having. I just started programming and am doing self exercises so I remember what I read and how it looks actually being done in a program, but doing this, i have come up with a syntax error. I am trying to use bolean statements with if/else if and else statements.
The problem I am getting is that during my else statement which is
else(age>21) {
cout "" You are not allowed in";
}
I keep getting an error that is tellingme that it is expecting a ; before the {
I don't know if this is allowed but for further help to you guys ill write my code out and tell you on what line the error is
#include <iostream>
usingnamespace std;
int main ()
int age,money;
cout <<"How old are you\n"
cin >> age;
cout <<"How much money do you have\n";
cin >>money;
if (age>21 && money>600) {
cout << "You are allowed in\n";
elseif (age>21||money>600) {
cout << "Stand by you may be allowed in";
}
else(age<21) {
cout << "Sorry you are not allowed in"
On the last else statment I keep getting the error:expected ';' before '{' token thing. I can fix it easily by putting the ; in, but I don't understand why it needs it. Also I woudl try putting a not statement in, but I still am a bit confused on how they work. Thanks in advance
Ok sorry for the latency, I have put up the code with the instructions you have given me, I am using codeblocks for my compiler and the only specific error it has is..
Line 26
error:expected ';' before '{' token
Im using Codeblocks, if there is anything i can do for you to help me, with other errors this program may have let me know.
I fixed the bit of code you put up. Your main error was that you put a condition after an else statement, so either use an else statement without a condition or just use an else if statement and put your conditions after it
ex. of else statement:
1 2
else
{cout<<"Sorry you are not allowed in";}
ex. of else if statement:
1 2
elseif (age<21)
{cout<<"Sorry you are not allowed in";}
See corrected code for more instructions, and other mistakes.
#include <iostream>
usingnamespace std;
int main ()
{
int age,money;
cout <<"How old are you\n"; // <---Missing a semicolon here
cin >> age;
cout <<"How much money do you have\n";
cin >>money;
if (age>21 && money>600) {
cout << "You are allowed in\n";
} // <---You didn't end your if statement.elseif (age>21||money>600) {
cout << "Stand by you may be allowed in";
}
else { // <--- For an else statement you cant have a condition// You can only have a condition with an else if statement.
cout << "Sorry you are not allowed in";
} // <---You didn't end your else statementreturn 0;
}
Just got my internet back and would just like to say I got the problems running with the help of both of you, will be using this site for more help in the future, great great people thanks :)!