0

I have one unspecified error in my program. The program plays rock paper scissors against the user. I didn't changed anything in the source code. But when I run the program and it came up with an unspecified error.

code:

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

console:

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====
Draken
  • 3,134
  • 13
  • 34
  • 54
  • 6
    "cannot open output file ./Debug/aiprogramproject.exe: Permission denied" looks like a very specified error. Check that the program isn't running. – molbdnilo Apr 19 '17 at 07:37
  • Your while-loop performs an assignment `restarting_game = (true)`, which then "returns" true. That is, it does not check if `restarting_game` is true or false, it loops forever. – Jonas Apr 19 '17 at 08:02
  • 1
    Possible duplicate of [Cannot open output file, permission denied](http://stackoverflow.com/questions/6875403/cannot-open-output-file-permission-denied) – cbuchart Apr 19 '17 at 08:49

1 Answers1

1

Make sure your program is not running. Make clean and then try make again.

DRoc101
  • 63
  • 8