2013-08-27 69 views
0

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

当我从函数getWinnings()中取出int b时,它会编译/运行,但如果我添加更多参数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"; 
} 
+0

当它说“这个项目还没有建成,你想现在建立它?”你必须点击“是”。 – 0x499602D2

+0

我点击是和没有。没有错误,没有程序,只是在构建日志中。就像我说的,它会编译如果我从函数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秒) –

+0

然后您必须运行该方案,打F9来做到这一点。 – 0x499602D2

回答

0

确保程序的最后一个实例没有运行。检查你的任务管理器,并强制关闭Slot Machine.exe,如果你看到它。

0

它可能是编译器的行为有趣,或者它可能是关于环境的东西。

编译器:

如果它只是导致它崩溃(这可能会保持代码::块从打开可执行文件,并让它给你的消息),编译一些奇怪的故障,那么我建议改变...

int getWinnings (int a,int b) 
{ 
    return a + b; 
}; 

...到#define getWinnings(a,b) (a + b)

环境:[我假设你正在使用Windows]

我有时会在两种情况下得到该通知。

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

第二个是Code :: Blocks在编写程序关闭文件之后,在Windows打开它以读取访问权之前查找可执行文件。在这种情况下,在构建它之后,如果它给出了消息,只需点击“否”,然后点击运行按钮(而不是Build &运行按钮)。

如果这些都不是问题,那么您可能遇到了文件访问问题,例如您不在管理员级别的帐户中,或者Code :: Blocks尚未被授予管理员级别的权限。尝试设置Code :: Blocks以管理员级别权限打开(在Windows 7上,这意味着您必须单击弹出窗口才能在每次打开时允许它),或者如果您不能这样做,那么也许改变你正在编译的目录。