2013-08-27 4 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 - (0 분, 1 초) 0 개의 오류, 0 개의 경고 (0 분, 1 초) –

+0

실행해야하는 "bin \ Debug \ Slot Machine.exe"obj \ Debug \ main.o 상태 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 & 헤더를 테스트하는 실제 프로그램 대신에 수정 한 헤더 파일에서 실행하십시오. 이 경우 원본 파일의 확장자를 잘못 지정했다면 확장명을 ".h"대신 ".c"또는 ".cpp"로 변경 한 다음 다시 엽니 다.

두 번째는 Code :: Blocks가 컴파일러가 파일을 작성한 후 파일을 닫은 후 Windows에서 파일을 열어 읽기 전에 해당 파일을 찾은 것입니다. 이 경우 빌드 한 후 메시지가 표시되면 "아니요"를 누르고 실행 버튼을 누릅니다 (빌드 & 실행 버튼이 아님).

이 두 가지 모두에 문제가없는 경우 관리자 수준 계정이 아니거나 Code :: Blocks에 관리자 수준 권한이 부여되지 않은 등 파일 액세스에 문제가있을 수 있습니다. Code : Blocks 설정을 관리자 수준의 권한으로 열어보십시오 (Windows 7에서는 열 때마다 팝업을 허용해야 함을 의미합니다). 그렇지 않으면 가능하지 않을 수도 있습니다. 컴파일하는 디렉토리를 변경하십시오.

관련 문제