2016-12-06 34 views
-5
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 

我不知道为什么,当我尝试输入嵌套,否则它跳过它,无论我按y或n,它是给出选项在两种情况下输入输入。有什么问题?为什么嵌套if语句不工作?

+3

请格式化代码,并要求实际问题 –

+3

我们需要一个可读[MCVE(http://stackoverflow.com/help/mcve)和明确的问题陈述能够理解这个问题。 –

+1

'if(op ='y'){'是一项任务。它总是如此,并设置为'y'。 – drescherjm

回答

1

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

这应该是一个双等于if (op == 'y') {

+0

非常感谢,现在已经修复。 :) –

+1

这就是为什么我们有这样的问题的意见和适当的密切的原因。 –

+0

@ManzarI。如果它对你有帮助,你可以接受我的答案 –