C++ 代码块中的问题编译程序

C++ 代码块中的问题编译程序,c++,codeblocks,C++,Codeblocks,我已经成功地编译/运行了其他程序,但当我尝试编译/运行下面的代码时,它会告诉我:“这个项目还没有建立,你想现在就建立它吗?” 当我将int b从函数getWinnings()中取出时,它将编译/运行,但如果我添加更多参数,code::blocks会给出上面的消息。这是什么原因造成的 #include <iostream> #include <ctime> #include <cstdlib> #include <strin

我已经成功地编译/运行了其他程序,但当我尝试编译/运行下面的代码时,它会告诉我:“这个项目还没有建立,你想现在就建立它吗?”

当我将int b从函数getWinnings()中取出时,它将编译/运行,但如果我添加更多参数,code::blocks会给出上面的消息。这是什么原因造成的

    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    #include <string>

    int gameCoins;

    using namespace std;

    void instructions();
    void playSlots();
    void spin();

    int main()
    {
    srand(time(NULL));
    instructions();
    playSlots();
    }

    void instructions()
    {
    cout << "\t\t" << "VIRTUAL SLOT MACHINE" << "\n\n";
    cout << "INSTRUCTIONS: " << endl << "You start with 500 coins. The game is over either when you run out of coins or you quit the game." << "\n";
    cout << "It will cost you 25 coins per spin. Good luck!" << "\n\n" ;
    }
    void playSlots()
    {
    string user_input;
    string replay_or_quit;

    while (replay_or_quit != "n" && replay_or_quit != "no")
    {
    gameCoins = 500;
    cout << "Coins: " << gameCoins << "\n";
    while (user_input != "spin" && user_input != "Spin")
    {
        cout << "Spin the wheels to start playing. Type 'spin' to begin" << "\n";
        cin >> user_input; cout << "\n\n";
    }
    spin();
    while (gameCoins > 0 && user_input != "no" && user_input != "n")
    {
        cout << "Spin again?" << "\n" << "Decision: ";
        cin >> user_input;
        if (user_input == "y" || user_input == "yes")
        spin();
    }
    if (gameCoins == 0)
    {
        cout << "You went broke. Play again?" << "\n" << "Decision: ";
        cin >> replay_or_quit;
    }
    else
    {
        cout << "Congratulations, you won " << gameCoins << " coins. Play again?" << "\n" << "Decision: ";
        cin >> replay_or_quit;
    }
}
}

    int getWinnings(int a, int b)
    {
    return (a+b);
    }
    void spin()
    {
int wheelOne_Top, wheelOne_Mid, wheelOne_Bot;
int wheelTwo_Top, wheelTwo_Mid, wheelTwo_Bot;
int wheelThree_Top, wheelThree_Mid, wheelThree_Bot;
int coinsWon;

gameCoins = gameCoins-25;
wheelOne_Top = (rand() % 3) + 1, wheelTwo_Top = (rand() % 3) + 1, wheelThree_Top = (rand() % 3) + 1;
wheelOne_Mid = (rand() % 3) + 1, wheelTwo_Mid = (rand() % 3) + 1, wheelThree_Mid = (rand() % 3) + 1;
wheelOne_Bot = (rand() % 3) + 1, wheelTwo_Bot = (rand() % 3) + 1, wheelThree_Bot = (rand() % 3) + 1;

while (wheelOne_Top == wheelOne_Mid || wheelOne_Top == wheelOne_Bot || wheelOne_Bot == wheelOne_Mid)
{
    wheelOne_Mid = (rand() % 3) + 1;
    wheelOne_Bot = (rand() % 3) + 1;
}
while (wheelTwo_Top == wheelTwo_Mid || wheelTwo_Top == wheelTwo_Bot || wheelTwo_Bot == wheelTwo_Mid)
{
    wheelTwo_Mid = (rand() % 3) + 1;
    wheelTwo_Bot = (rand() % 3) + 1;
}
while (wheelThree_Top == wheelThree_Mid || wheelThree_Top == wheelThree_Bot || wheelThree_Bot == wheelThree_Mid)
{
    wheelThree_Mid = (rand() % 3) + 1;
    wheelThree_Bot = (rand() % 3) + 1;
}

cout << "Coins: " << gameCoins << endl << endl;
cout << "\t\t\t" << wheelOne_Top << " " << wheelTwo_Top << " " << wheelThree_Top << "\n";
cout << "\t\t\t" << wheelOne_Mid << " " << wheelTwo_Mid << " " << wheelThree_Mid << "\n";
cout << "\t\t\t" << wheelOne_Bot << " " << wheelTwo_Bot << " " << wheelThree_Bot << "\n\n";

coinsWon = getWinnings(wheelOne_Top, wheelOne_Mid);
gameCoins = coinsWon + gameCoins;

if (gameCoins > 0)
    cout << "You won " << gameCoins << " coins!" << "\n" << "Total Coins: " << gameCoins << "\n\n";
else
    cout << "You lost 25 coins!" << "\n" << "Total coins: " << gameCoins << "\n\n";
}
#包括
#包括
#包括
#包括
智力游戏币;
使用名称空间std;
无效指令();
空播放槽();
空位自旋();
int main()
{
srand(时间(空));
指令();
playSlots();
}
无效指令()
{

无法确保程序的最后一个实例尚未运行。请检查您的任务管理器,如果看到它,请强制关闭Slot Machine.exe。

可能是编译器行为滑稽,也可能是环境问题

编译器:

如果只是编译器出现了一些奇怪的小故障,导致它崩溃(这可能会阻止Code::Blocks打开可执行文件,并让它向您发送该消息),那么我建议更改

int getWinnings (int a,int b)
{
    return a + b;
};
…到
#定义getWinnings(a,b)(a+b)

环境:

[我假设您使用的是Windows。]

我有时会收到通知,有两种情况

首先,我无意中在我正在修复的头文件上运行Build&Run,而不是在我正在使用测试头的实际程序上运行。在这种情况下,如果给源文件的扩展名错误,请关闭它,将扩展名改为“.c”或“.cpp”而不是“.h”,然后重新打开它

第二个是Code::Blocks在Windows打开可执行文件以进行读取访问之前,在编译器写入文件后关闭了该文件。在这种情况下,在构建该文件后,如果它向您发出消息,只需单击“否”,然后单击“运行”按钮(而不是“构建和运行”按钮)


如果这两个都不是问题,您可能在文件访问方面有问题,例如您不在管理员级别的帐户上,或者代码::Blocks未被授予管理员级别的权限。请尝试使用管理员级别的权限打开设置代码::Blocks(在Windows 7上,这意味着您必须在每次打开时单击弹出窗口以允许它),或者如果您不能这样做,则可能需要更改正在编译的目录。

当它显示“此项目尚未生成,是否立即生成?”时,您必须单击“是”。我单击了yes and nothing。没有错误,没有程序,只有构建日志中的这个。正如我所说,如果我从函数getWinnings()中删除int b,它将被编译,但一旦我添加更多参数,我将一无所获。-------构建:在老虎机中调试(编译器:GNU GCC编译器)---------------mingw32-g++.exe-o“bin\Debug\Slot Machine.exe”obj\Debug\main.o进程终止,状态为0(0分钟,1秒)0个错误,0个警告(0分钟,1秒),然后您必须运行程序,按F9执行此操作。我以前编译/运行过程序。这不是问题