this is my code for bankingMenu, i keep getting that error and I've done what i can to my knowledge to try and fix this but to no avail.. any suggestions?
bool bankingMenu(bool menuFlag) //banking menu
{
char choice;
bool flag = false;
bool flag2 = menuFlag;
//print login menu
cout<<"\n";
cout<<"\n";
cout<<" BANK MENU"<<endl;
cout<<"----------------------------------------------------------------------"<<endl;
cout<<endl;
cout<<" A. SHOW ACCOUNT BALANCE"<<endl;
cout<<" C. MAKE A WITHDRAWAL"<<endl;
cout<<" D. WRITE A CHECK"<<endl;
cout<<" E. SHOW ALL TRANSACTIONS"<<endl;
cout<<" F. LOGOFF ACCOUNT"<<endl;
cout<<"\n";
cout<<"\n";
cout<<"PLEASE ENTER YOUR SELECTION"<<endl;
//enter choice of action
cin>> choice;
//change input to uppercase
choice = toupper(choice);
//input validation for choice
while( flag == false)
{
if(choice != 'A' && choice != 'B' && choice != 'C' && choice!= 'D' && choice!= 'E' && choice!= 'F')
{
cout<<"\n";
cout<<"\n";
cout<<"ERROR!! YOU HAVE ENTERED AN INVALID CHOICE. PLEASE ENTER A VALID OPTION."<<endl;
cin>> choice;
//change input to uppercase
choice = toupper(choice);
continue;
}
flag=true;
}
//switch for action to be taken with the choice value
switch (choice)
{
case 'A' : cout<< "YOU HAVE ENTERED A. \n";
break;
case 'B' : cout<< "YOU HAVE ENTERED B. \n";
break;
case 'C' : cout<< "YOU HAVE ENTERED C. \n";
break;
case 'D' : cout<< "YOU HAVE ENTERED D. \n";
break;
case 'E' : cout<< "YOU HAVE ENTERED E. \n";
break;
case 'F' : flag2= false;
//returns to the login menu
return flag2;
break;
default: ;
}}
how can i fix this error?
First, it's a warning, not an error. Your code will compile and run, but the warning is the compiler saying "This might not do what you thought it did! You might want to double-check it!"
And the reason it says "not all control paths return a value" is that your function doesn't always return anything. Specifically, it only returns anything if you enter 'F'. To fix it, make your function always return something.
add return flag2;
(or true or false) at the end of the method to be sure you have a return value even if choice is something other than 'F'.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.