"if statement missing (" help
Feb 17, 2015 at 12:55pm UTC
My homework is due two days from now and I have been struggling with this error I can't seem to fix. We were to create a program that lets the user sign up and log in and I really don't know what's the problem with my code. There's also an error called "Compound statement missing }".
Lines 27 and 40 was said to have the "if statement missing (" error and line 94 had the "Compound statement missing }"
Please help. :(
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main ()
{
clrscr();
char ans, un[30], pw[30], UN[30], PW[30], answ, FN[30], SN[30];
int x, y;
cout<<"Do you have an account? (y/n)" ;
cin>>ans;
if (ans=='y' )
{
cout<<"Please log in." ;
cout<<"/nUsername: " ;
cin>>un;
cout<<"/nPassword: " ;
cin>>pw;
x=strcmp(un,UN);
y=strcmp(pw,PW);
if (x==0 && y==0)
{
cout<<"Log in successful. \n\n" ;
cout<<"Welcome, " <<FN<<" " <<SN;
}
if else (x!==0)
{
cout<<"Log in error.\nUsername not found." ;
}
if else (y!==0)
{
cout<<"Log in error.\nIncorrect password." ;
}
else
{
cout<<"Log in error. Please try again." ;
}
}
if else (ans=='n' )
{
cout<<"Would you like to sign up? (y/n)" ;
cin>>answ;
if (answ=='y' )
{
cout<<"Enter first name: " ;
cin>>FN;
cout<<"Enter last name: " ;
cin>>SN;
cout<<"Enter desired username: " ;
cin>>UN;
cout<<"Enter password: " ;
cin>>PW;
cout<<"Thank you for signing up." ;
cout<<"Please log in." ;
cout<<"/nUsername: " ;
cin>>un;
cout<<"/nPassword: " ;
cin>>pw;
if (x==0 && y==0)
{
cout<<"Log in successful. \n\n" ;
cout<<"Welcome, " <<FN<<" " <<SN;
}
if else (x!==0)
cout<<"Log in error.\nUsername not found." ;
if else (y!==0)
cout<<"Log in error.\nIncorrect password." ;
else
cout<<"Log in error. Please try again." ;
}
else if (answ=='n' )
{
cout<<"Goodbye." ;
}
else
{
cout<<"That's not a valid answer." ;
cout<<"\nJesus." ;
cout<<"\nThere are already choices there." ;
cout<<"\nCan't you see?" ;
cout<<"\nUgh." ;
}
}
else
{
cout<<"That's not a valid answer." ;
cout<<"\nJesus." ;
cout<<"\nThere are already choices there." ;
cout<<"\nCan't you see?" ;
cout<<"\nUgh." ;
}
getch();
}
Last edited on Feb 17, 2015 at 12:58pm UTC
Feb 17, 2015 at 1:01pm UTC
if else
should be else if
.
Feb 17, 2015 at 1:18pm UTC
I just changed all the
if else
to
else if
. I now have 8 errors..
Expression Syntax in lines 27 & 65
If statement missing } in lines 39 & 77
Misplaced else in lines 40 & 78
Compound statement missing in lines 100 and 101
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main ()
{
clrscr();
char ans, un[30], pw[30], UN[30], PW[30], answ, FN[30], SN[30];
int x, y;
cout<<"Do you have an account? (y/n)" ;
cin>>ans;
if (ans=='y' )
{
cout<<"Please log in." ;
cout<<"/nUsername: " ;
cin>>un;
cout<<"/nPassword: " ;
cin>>pw;
x=strcmp(un,UN);
y=strcmp(pw,PW);
if (x==0 && y==0)
{
cout<<"Log in successful. \n\n" ;
cout<<"Welcome, " <<FN<<" " <<SN;
}
else if (x!==0)
{
cout<<"Log in error.\nUsername not found." ;
}
else if (y!==0)
{
cout<<"Log in error.\nIncorrect password." ;
}
else
{
cout<<"Log in error. Please try again." ;
}
}
else if (ans=='n' )
{
cout<<"Would you like to sign up? (y/n)" ;
cin>>answ;
if (answ=='y' )
{
cout<<"Enter first name: " ;
cin>>FN;
cout<<"Enter last name: " ;
cin>>SN;
cout<<"Enter desired username: " ;
cin>>UN;
cout<<"Enter password: " ;
cin>>PW;
cout<<"Thank you for signing up." ;
cout<<"Please log in." ;
cout<<"/nUsername: " ;
cin>>un;
cout<<"/nPassword: " ;
cin>>pw;
if (x==0 && y==0)
{
cout<<"Log in successful. \n\n" ;
cout<<"Welcome, " <<FN<<" " <<SN;
}
else if (x!==0)
{
cout<<"Log in error.\nUsername not found." ;
}
else if (y!==0)
{
cout<<"Log in error.\nIncorrect password." ;
}
else
{
cout<<"Log in error. Please try again." ;
}
}
else if (answ=='n' )
{
cout<<"Goodbye." ;
}
else
{
cout<<"That's not a valid answer." ;
cout<<"\nJesus." ;
cout<<"\nThere are already choices there." ;
cout<<"\nCan't you see?" ;
cout<<"\nUgh." ;
}
}
else
{
cout<<"That's not a valid answer." ;
cout<<"\nJesus." ;
cout<<"\nThere are already choices there." ;
cout<<"\nCan't you see?" ;
cout<<"\nUgh." ;
}
getch();
}
Also, please don't mind the lines 94-97..
Feb 17, 2015 at 1:23pm UTC
If you are using vi or vim, you can match your braces with the '%' character.
Feb 17, 2015 at 2:23pm UTC
The not-equal-to operator is !=.
Topic archived. No new replies allowed.