2016-12-06 85 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。如果它對你有幫助,你可以接受我的答案 –