こんにちは私は、ユーザーが入力したメニューの選択に基づいて実行する多くの機能を実行するプログラムを作成しています。私の質問は、次のコードがユーザー入力の違いに応答しない理由です。たとえば、メニュー選択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を検証して返します。 –