2016-12-06 12 views
-1

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

=演算子は代入用です。 ==を使用します。 – MordechayS

+1

なぜ、(初期化されていない) 'menuchoice'の値を' 'get_selection()'に渡すのですか? 'menuchoice'の値はどこにも設定しません! –

+0

@ piet.tメニュー選択入力を扱う機能を持っています。ユーザーの応答1-5を検証して返します。 –

答えて

1

'=' 割り当て ための例である:。INT A = 5という変数に5を割り当てます。

urの場合...すべてのur '=' to '=='を変更する必要があります。 '=='は比較のためです。 例:if(a==5)cout<<a; uは代わりに... 5 ...

に等しい場合にのみ、変数menuchoice uは関数getselectionのパラメータとしてそれを取るべきではありません...値を取るdoesntのをすることができます印刷しますそれは他の部分を含める

menuchoice=getselection()このような

選択肢の何かを返すように...それは、プログラム全体にいくつかのより多くの意味を与える代わりに、しばらく時間がない...できるだけシンプルにしてください:)

+0

何が正直な瞬間..私はそれを言った前に私は2つを気づかなかった。大変ありがとう!自分のプログラム全体を見て、私の機能のいくつかが変わっているのをなぜ知りたいのですか?もしそうなら、ここにコードhttp://pastebin.com/fxhPFeec –

+0

へのリンクがあります。確かに... @ChrisKeenan – Akilesh