2017-11-06 20 views
-5

if文が機能していないようですが、「一致しないと違法です」というエラーメッセージが表示されるようです。どんな助けも素晴らしいだろう、ありがとう。不一致の場合は一致しません

#include "stdafx.h" 
#include "windows.h" 
#include "iostream" 

using namespace std; 

int igame = 0; 

int main() 
{ 
    Sleep(1000); 
    cout << "welcome to the Wild Casino!"; 
    Sleep(1000); 
    cout << "\nplease select a game to play. 1 for Slots, 2 for Roulette, and 3 for Blackjack: "; 
    cin >> igame; 

    if (igame == 1); 
    { 
     cout << "\nWelcome to Slots"; 

    } 
    else if (igame == 2); 
    { 
     cout << "\nWelcome to Roulette"; 
    } 
    else 
    { 
     cout << "\nWelcome to Blackjack"; 
    } 


Sleep(1000000); 
return 0; 

}

+0

を'if(igame == 1);'、 'else if(igame == 2);'セミコロンを削除する';'。 – DimChtz

+0

セミコロンを確認してください – DAle

+0

すごくうれしい答えをいただきありがとうございます! – greenedar

答えて

1
if (igame == 1); 

あなたは最後に余分なセミコロンを持っている - これはあなたのコードが病気に形成されたプログラムを作成

if (igame == 1) { } 

と同等です:

if (igame == 1) { } 

{ // block not attached to if 
    cout << "\nWelcome to Slots"; 
} 
else if (igame == 2) { } // this else has no matching if 
{ 
    cout << "\nWelcome to Roulette"; 
} 
else // this else has no matching if 
{ 
    cout << "\nWelcome to Blackjack"; 
}