2016-03-22 16 views
0

Alt kısımda çalışmaz ise; evcil hayvanların gerçekten var olmadığını söylüyor."Kodunuz Asla Yürütülmez" Bildirimi

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

kaldırmak gerekir sonlarına doğru noktalı virgül ;? – juanchopanza

cevap

8

Daha sonra, eğer Durumu için

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

(sıfır olmayan bir değer olarak) Aksi takdirde

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

, 'y' her zaman true olarak değerlendirilecektir eğer değişmelidir (pets == 'Y' || 'y') da her zaman true olacaktır.

Ve diğer koşullar için de aynı şey geçerlidir.

4

songyuanyao en answer ekleme, sahip başka sözdizimi hatası

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

Not açıklamada, bu Sorunuz nedir

İlgili konular