validation and menu call

case 1 : {

char OTX;
cout<<"Enter the code reserved for staff and faculty :"<<endl;
cin>>OTX;
char answer;
if (answer != 'OTX' && answer != 'otx' ) {
cout<<"Access not authorized!\n"<<endl;

cout<<"Please choose in which parking slot :\n"
<<"Please choose from the following options :\n\n"
<<"1-I'm faculty ,staff or personal.\n"
<<"2-I'm a student.\n"
<<"3-I'm a visitor.\n"
<<"4-I changed my mind and would like to exit.\n";
cin>>choice;
}

hi everyone . So I have this piece of code where I want to be able to validate in upper and lower case a code reserved for some people and if its wrong I should send him back to the menu to choose an option . I.m getting
Code:
char answer
uninitialized and I want to also if I can send the user back to menu without writing it again in the case . thx u
They've input the code into the variable called OTX, not answer. Note that a char holds one character and you're expecting them to input a three letter value "OTX" - sounds like the variable should be a string?

1
2
3
4
5
char OTX;
cout<<"Enter the code reserved for staff and faculty :"<<endl;
cin>>OTX; // input entered here into OTX
char answer; // uninitialized variable, no input to this variable
if (answer != 'OTX' && answer != 'otx' )


You can use a loop if you need to repeat code. Is it the choice from the menu of parking slots that goes into the switch case? Loop might be - Display menu - get input - validate code - if access not authorized, repeat.
yes I fixed it already but thx for ur time

but actually I have another question
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
case 1 : {

cout<<"Enter the code reserved for staff and faculty :"<<endl;
string answer;
cin>> answer;
if (answer != "OTX" && answer != "otx" ) {
	cout<<"Access not authorized!\n"<<endl; 

cout<<"Please choose in which parking slot :\n" 
    <<"Please choose from the following options :\n\n"
    <<"1-I'm faculty ,staff or personal.\n"
    <<"2-I'm a student.\n"
    <<"3-I'm a visitor.\n"
    <<"4-I changed my mind and would like to exit.\n";
cin>>choice;		
}


so this code is working gd if user entered otx another task is done if not he should be sent to the menu I wrote u see? now that menu is already written in main to ask user but can we send user back to the menu without writing it each time . thx
Topic archived. No new replies allowed.