2016-03-22 5 views
0

下部のif elseは動作しません。ペットは本当に存在しないと言います。"あなたのコードは決して実行されません"というステートメントの場合

void checkIn() 
{ 

    int roomNum = 0; 
    int party = 0; 
    char pets; 
    char smoke; 

    cout << "----------------------------" << endl; 
    cout << "Welcome to Shrek's Swamp Inn" << endl << endl; 

    cout << "How many people are In your party? " << endl; 
    cin >> party; 

    cout << "Do you have pets? (Y/N)" << endl; 
    cin >> pets; 

    switch (pets) 
    { 
     case 'Y' : case 'y': 
      cout << "GTLO" << endl; 
      break; 
     case 'N' : case 'n': 
      cout << "cool cool" << endl; 
      break; 
     default : 
      cout << "User error" << endl; 
    } 

    cout << "Do you want a smoke room? (Y/N) " << endl; 
    cin >> smoke; 

    switch (smoke) 
    { 
     case 'Y' : case 'y': 
      cout << "GTLO" << endl; 
      break; 
     case 'N' : case 'n': 
      cout << "cool cool" << endl; 
      break; 
     default : 
      cout << "User error" << endl; 
    } 

    if((pets == 'Y' || 'y') && (smoke == 'Y' || 'y')){ 
     roomNum = rand() % 4 + 1; 
     cout << "Your room is " << roomNum << "S" << endl; 
    } 
    else if((pets == 'Y' || 'y') && (smoke == 'n' || 'N')){ 
     roomNum = rand() % 8 + 5; 

     cout << "Your room is " << roomNum << "P" << endl; 
    } 
    else if((pets == 'n' || 'N') && (smoke == 'n' || 'N'));{ 
     roomNum = rand() % 15 + 9; 

     cout << "Your room is " << roomNum << "R" << endl; 
    } 

} 
+0

削除する必要があるの終わりに向かってセミコロン;? – juanchopanza

答えて

8

そのあと、もし条件の条件

(pets == 'Y' || 'y') 

(非ゼロ値など)それ以外の場合は

(pets == 'Y' || pets == 'y') 

'y'には常にtrueとして評価される場合を変更する必要があります(pets == 'Y' || 'y')は常にtrueになります。

他のすべての条件でも同じです。

4

songyuanyaoのanswerに加えて、あなたが持っている別の構文エラー

else if((pets == 'n' || 'N') && (smoke == 'n' || 'N'));{ 

注文で、あなたはこれがあなたの質問は何である

関連する問題