你好我正在編寫一個程序,運行很多基於用戶輸入的菜單選項運行的功能,我不會包括在內。我的問題是爲什麼下面的代碼沒有響應用戶輸入的差異。例如,如果我進入菜單選擇1或4,這並不重要,並會回到菜單選擇1.我知道這與我的=或==運營商有關,但都沒有產生正確的結果,所以我不知道該怎麼做做。請幫忙! 。關於運營商的簡單查詢
int main() //Handles the if statements concerning the menu of the program
{
int r_identifier[42]; //Variable Declaration
int year_entry[42];
double gpa_entry[42];
string student_name[42];
int index = 0;
int menuchoice; //Variable Declaration
do
{
print_menu(); //Calls function to print menu
get_selection(menuchoice); //Calls function to get the menu selection
if (menuchoice = 1) //Calls the function to input a new user
{
input_new_student(student_name, r_identifier, gpa_entry, index, year_entry);
cout << "\nThe student with R#" << r_identifier[index] << " was created. " << endl;
index++;
}
else if (menuchoice = 2) //Prints all
{
print_all();
}
else if (menuchoice = 3) //Prints statistics about all students in a particular year
{
int year_view;
print_by_year(student_name, r_identifier, gpa_entry, index, year_entry);
}
else if (menuchoice = 4) //Prints statistics about all entered users
{
print_statistics();
}
else if (menuchoice = 5) //Quits the program
{
cout << "Have a good summer! ";
cout << endl;
}
} while (menuchoice != 5);
return 0;
}
=運算符用於賦值。使用==。 – MordechayS
爲什麼要將(未初始化)'menuchoice'的值傳遞給''get_selection()'?你不要在任何地方設置'menuchoice'的值! –
@ piet.t我有一個處理菜單選擇輸入的函數。它驗證並返回用戶響應1-5。 –