2017-04-19 30 views
0

我的程序中有一個未指定的錯誤。該程序針對用戶播放岩石剪刀。我沒有改變源代碼中的任何東西。但是,當我運行該程序,並提出了一個未明確的錯誤。我在我的基本C++程序中有一個未指定的錯誤

代碼:

#include <stdio.h> 

#include <string> 
#include <iostream> 
#include <stdlib.h> 
#include <windows.h> 
#include "math.h" 
#include <time.h> 
#include <cstdlib> 

void begin_game(); 

using namespace std; 

int main(){ 
    SetConsoleTitle("Rock Paper Scissors"); 

    string enter_to_continue; 


    cout<<"Welcome to rock paper scissors \n"; 
    cout<<"Type begin to start \n"; 
    cin>>enter_to_continue; 

    if (enter_to_continue == "begin"){ 
     begin_game(); 
    } 

    return 0; 
} 



//begin game function 
    void begin_game(){ 

    cout<<"\n"; 

    string player_input; 

    bool restarting_game = true; 
    //restarting game while loop 
    while(restarting_game = (true)){ 

     restarting_game = false; 

     int seed_random = seed_random + 3; 
     srand(seed_random); 
     int ai_random = rand() % 3+1; 

     cout<<seed_random<<endl; 
     cout<<"r = rock \n"; 
     cout<<"p = paper \n"; 
     cout<<"s = scissors \n \n"; 

     cout<<"Type r, p, or s \n"; 
     cout<<"You can type exit to exit game \n \n"; 
     cin>>player_input; 

     if(player_input == "exit"){ 
     restarting_game = false; 
     cout<<"\n"; 
     exit(0); 
     } 
     else{ 
     //rock vs ai 
     if(player_input == "r" && ai_random == 1){ 
     cout<<"The computer chose rock \n"; 
     cout<<"ITS A TIE RESTARTING \n \n \n"; 
     cout<<"\n \n \n"; 
     bool restarting_game = true; 
     } 
     else if(player_input == "r" && ai_random == 2){ 
     cout<<"The computer chose paper \n"; 
     cout<<"YOU LOST RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n"; 
     cout<<"\n \n \n"; 
     restarting_game = true; 
     } 
     else if(player_input == "r" && ai_random == 3){ 
     cout<<"The computer chose rock \n"; 
     cout<<"YOU WON RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n "; 
     cout<<"\n \n \n"; 
     restarting_game = true; 
     } 

     //paper vs ai 
     if (player_input == "p" && ai_random == 1){ 
     cout<<"The computer chose rock \n"; 
     cout<<"YOU WON RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n "; 
     cout<<"\n \n \n"; 
     restarting_game = true; 
     } 
     else if (player_input == "P" && ai_random == 2){ 
     cout<<"The computer chose paper \n"; 
     cout<<"ITS A TIE RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n "; 
     cout<<"\n \n \n"; 
     restarting_game = true; 
     } 
     else if (player_input == "p" && ai_random == 3){ 
     cout<<"The computer chose rock \n"; 
     cout<<"YOU LOST RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n "; 
     cout<<"\n \n \n"; 
     restarting_game = true; 
     } 

     //scissor vs ai 
     if (player_input == "s" && ai_random == 1){ 
      cout<<"The computer chose rock \n"; 
      cout<<"YOU LOST RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n "; 
      cout<<"\n \n \n"; 
      restarting_game = true; 
     } 
     else if(player_input == "s" && ai_random == 2){ 
      cout<<"The computer chose paper \n"; 
      cout<<"YOU WON RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n "; 
      cout<<"\n \n \n"; 
      restarting_game = true; 
     } 
     else if(player_input == "s" && ai_random == 3){ 
      cout<<"The computer chose rock \n"; 
      cout<<"ITS A TIE RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n "; 
      cout<<"\n \n \n"; 
      restarting_game = true; 
     } 
     } 
    } 
    } 

控制檯:

C:\Windows\system32\cmd.exe /C ""C:/Program Files (x86)/CodeBlocks/MinGW/bin/mingw32-make.exe" -j4 SHELL=cmd.exe -e -f Makefile" 
"----------Building project:[ aiprogramproject - Debug ]----------" 
mingw32-make.exe[1]: Entering directory 'C:/Users/lisa/Desktop/codelight c++/aiprogram/aiprogramproject' 
"C:/Program Files (x86)/CodeBlocks/MinGW/bin/g++.exe" -o ./Debug/aiprogramproject @"aiprogramproject.txt" -L. 
C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw32/bin/ld.exe: cannot open output file ./Debug/aiprogramproject.exe: Permission denied 
collect2.exe: error: ld returned 1 exit status 
mingw32-make.exe[1]: *** [Debug/aiprogramproject] Error 1 
aiprogramproject.mk:78: recipe for target 'Debug/aiprogramproject' failed 
mingw32-make.exe[1]: Leaving directory 'C:/Users/lisa/Desktop/codelight c++/aiprogram/aiprogramproject' 
mingw32-make.exe: *** [All] Error 2 
Makefile:4: recipe for target 'All' failed 
====1 errors, 0 warnings==== 
+6

「無法打開輸出文件./Debug/aiprogramproject.exe:權限被拒絕」看起來像一個非常規定的錯誤。檢查程序沒有運行。 – molbdnilo

+0

你的while循環執行一個賦值'restarting_game =(true)',然後「返回」true。也就是說,它不檢查「restarting_game」是true還是false,它會永遠循環。 – Jonas

+1

可能重複的[無法打開輸出文件,權限被拒絕](http://stackoverflow.com/questions/6875403/cannot-open-output-file-permission-denied) – cbuchart

回答

1

確保程序沒有運行。做清潔,然後再試一次。

相關問題