其他非法,没有匹配如果

  • 本文关键字:如果 非法 其他 c++
  • 更新时间 :
  • 英文 :


似乎我的if语句不起作用,并且我收到"非法否则不匹配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;

}

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";
}

相关内容

最新更新