你好我正在编写一个程序,运行很多基于用户输入的菜单选项运行的功能,我不会包括在内。我的问题是为什么下面的代码没有响应用户输入的差异。例如,如果我进入菜单选择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。 –