为什么嵌套if语句不起作用?

时间:2016-12-06 19:21:23

标签: c++

case 1:
    {
        insert_menu();
        donor[turn].inputData();
        ::turn++; //accessing global variable
        char c = '\0';
        while (c != '0') {
            cout << "Press 1 to save, 0 to not save: ";
            cin >> c;
            fflush(stdin);
            if (c == '1') {
                cout << "Record saved successfully.";
                cout << "\nWant to insert another record? [y/n]: ";
                char op = '\0';
                cin >> op;
                //fflush(stdin);
                if (op = 'y') {
                    cout << "Enter another record\n\n";
                    donor[::turn].inputData();
                    cout << "Record entered successfully\n";
                    ::turn++; //increment to global variable turn
                } //end scope of nested if
                else {
                    cout << "Press Enter to return to main menu";
                    //fflush(stdin);
                //  getchar();
                    break;
                } //end scope of nested if
            } //end scope of first if
            else {
                ::turn--;
                cout << "Record not saved! You are being redirected to Main Menu" << endl;
                system("pause");
                //break;
            }
        } //end scope of while
    } // end scope of case 1
    break; //exiting case 1

我不知道为什么,当我尝试输入嵌套if else跳过它时,无论是按y还是n,它都可以选择在两种条件下输入输入。问题是什么?

1 个答案:

答案 0 :(得分:1)

我认为if (op = 'y') {行是罪魁祸首。

它应该是双等于if (op == 'y') {