这是我的bankMenu的代码,我一直收到这个错误,我已经尽我所知来尝试解决这个问题,但无济于事......有什么建议吗?
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: ;
}}
我该如何修复此错误?
答案 0 :(得分:0)
首先,这是一个警告,而不是错误。您的代码将编译并运行,但警告是编译器说“这可能不会按照您的想法执行!您可能需要仔细检查它!”
它说“并非所有控制路径返回值”的原因是你的函数并不总是返回任何东西。具体来说,只有输入'F'才会返回任何内容。要修复它,让你的函数总是返回一些东西。
答案 1 :(得分:0)
在方法结尾处添加return flag2;
(或true或false)以确保您具有返回值,即使选项不是“F”。