Upon asking recommendee, the R works and N works. But I want to add an else so that pressing buttons other than R/r & N/n will say wrong input code. But it tells me this (error: else without previous if)
Ive been adding this after cout<<"Rejected"<<endl;
1 2
else
cout<<"Wrong input"<<endl;
Also another problem when pressing R/r works fine telling Accepted but it doesnt end the program.
#include<iostream>
usingnamespace std;
main()
{float h,a;
char cc,rc;
cout<<"Are you a recommendee of Jedi Master Obi Wan? Press R/r if yes and N/n if no."<<endl;
cin>>rc;
if (rc=='R'||rc=='r')
cout<<"Accepted"<<endl;
elseif (rc=='N'||rc=='n')
cout<<"Enter your height: ";
cin>>h;
cout<<"Enter your age: ";
cin>>a;
cout<<"Enter citizenship code, Press C/c if your Endor and N/n if not: ";
cin>>cc;
if (h>=200)
if (a>=21 && a<=25)
if (cc=='C'||cc=='c')
cout<<"Accepted."<<endl;
else
cout<<"Rejected"<<endl;
system("PAUSE");
}
But it tells me this (error: else without previous if)
I get no such error when I compile what you posted.
lines 12-23: Only line 12 is conditional upon the elseif on line 11. This isn't Python. Indentation has no bearing on execution in C++. If you want more than one statement to be conditional, use { }.
#include<iostream>
usingnamespace std;
main()
{float h,a;
char cc,rc;
cout<<"Are you a recommendee of Jedi Master Obi Wan? Press R/r if yes and N/n if no."<<endl;
cin>>rc;
if (rc=='R'||rc=='r')
cout<<"Accepted"<<endl;
elseif (rc=='N'||rc=='n')
{cout<<"Enter your height: ";
cin>>h;
cout<<"Enter your age: ";
cin>>a;
cout<<"Enter citizenship code, Press C/c if your Endor and N/n if not: ";
cin>>cc;
if ((h>=200) && (a>=21 && a<=25) &&(cc=='C'||cc=='c'))
cout<<"Accepted."<<endl;
else
cout<<"Rejected"<<endl;}
else
cout<<"Invalid recommendee code!"<<endl;
system("PAUSE");
}
Thanks for the help. I just added {} so that the else im talking about would trigger continue on the else if right? also its working without int main() and return 0;