Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;
bool win;
int winnings;
int draws;
int loses;
string comChoice;
string playerChoice;

void winGame () {
cout << "You won! Play again?" <<endl;
cout << "Type y/n" <<endl;
                    char x;
                    cin >> x;
                        if (x == 'y') {
                        beginGame();
                        } else if ('n'){
                        cout << "Game Stopped." <<endl;
                        cout << "Number of Draws: " <<draws << endl;
                        cout << "Number of Loses: " <<loses << endl;
                        cout << "Number of Wins: " << winnings << endl;
                        win = true;
                        }
}

void drawGame (){
    ++draws;
    cout << "Draw! Try again" << endl;
return;
}

void lose () {
cout << "You lose! Try again?" <<endl;
                cout << "Type y/n" <<endl;
                    char feedback;
                    cin >> feedback;
                        if (feedback == 'y') {
                        beginGame();
                        } else if ('n'){
                        cout << "Game Stopped." <<endl;
                        cout << "Number of Draws: " <<draws << endl;
                        cout << "Number of Loses: " <<loses << endl;
                        cout << "Number of Wins: " << winnings << endl;
                        }
}

void beginGame() {
cout << "Welcome to the Rock, Paper and Scissors Game!" <<endl;
    cout << "Let's begin. Type <rock, paper, scissors> for your choice!" <<endl;
    cin >> playerChoice;
    srand(time(0));
    int randomizer = 1+(rand()%3);
        if (randomizer == 1)
        comChoice = "rock";
        if (randomizer == 2)
        comChoice = "paper";
        if (randomizer == 3)
        comChoice = "scissors";

            do {
                if (playerChoice == comChoice) {
                drawGame();
                }

                if (playerChoice == "rock" && comChoice == "paper")
                ++loses;
                lose();

                if (playerChoice == "rock" && comChoice == "scissors")
                ++winnings;
                winGame();

                if (playerChoice == "paper" && comChoice == "rock")
                ++winnings;
                winGame();

                if (playerChoice == "paper" && comChoice == "scissors")
                ++loses;
                lose();

                if (playerChoice == "scissors" && comChoice == "rock")
                ++loses;
                lose();

                if (playerChoice == "scissors" && comChoice == "paper")
                ++winnings;
                winGame();


            }while (win != true);

}


int main () {
beginGame();
return 0;
}
share|improve this question

closed as off topic by Jonathan Hobbs, Byte56, Noctrine Jun 24 '12 at 17:15

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
You might want to add what error you are receiving and with what exact message or what ever you want us to tell you. –  Nitram Jun 24 '12 at 11:29
    
it says undeclared scope in beginGame –  Rianelle Jun 24 '12 at 11:34
1  
Hi Rianelle - I have never seen an error message saying "Undeclared scope" in C++ before, and in fact this is my top Google hit for "c++ undeclared scope" so this is strange. You need to copy and paste the exact error message, not retype it, so that we can see the exact wording and the line number. It also helps to know what C++ compiler you are using. Finally, this problem is about C++ rather than games specifically, so it's a better fit for Stackoverflow.com. –  Kylotan Jun 24 '12 at 11:55
3  
-1 For a code dump with nothing else stated. –  Jonathan Hobbs Jun 24 '12 at 12:03

2 Answers 2

You need to work on how you ask questions, because as it is now, you're not even asking anything.

You probably want to know why the program doesn't compile, and I will tell you this: how would a function know about another function if you didn't tell the program that it exists yet (in C++)?

share|improve this answer
    
To be fair, most languages don't require forward declarations. –  Kylotan Jun 24 '12 at 12:48
    
You are perfectly correct, edit made for clarity. –  spektre Jun 24 '12 at 12:51

Your winGame function calls the beginGame function which doesn't exists yet. So you need to declare it before even if you write the function later in the code.

Furthermore you don't use braces in your multi-lines conditional statements, so I had to fix that too. And finally I modified the drawGame function to avoid infinite loop because of the braces modifications.

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

using namespace std;
bool win;
int winnings;
int draws;
int loses;
string comChoice;
string playerChoice;

void beginGame(); // forward declaration of the missing function

void winGame ()
{
    cout << "You won! Play again?" <<endl;
    cout << "Type y/n" <<endl;
    char x;
    cin >> x;
    if (x == 'y') {
        beginGame();
    } else if ('n') {
        cout << "Game Stopped." <<endl;
        cout << "Number of Draws: " <<draws << endl;
        cout << "Number of Loses: " <<loses << endl;
        cout << "Number of Wins: " << winnings << endl;
        win = true;
    }
}

void drawGame ()
{
    ++draws;
    cout << "Draw! Try again" << endl;
    //return;
    beginGame();
}

void lose ()
{
    cout << "You lose! Try again?" <<endl;
    cout << "Type y/n" <<endl;
    char feedback;
    cin >> feedback;
    if (feedback == 'y') {
        beginGame();
    } else if ('n'){
        cout << "Game Stopped." <<endl;
        cout << "Number of Draws: " <<draws << endl;
        cout << "Number of Loses: " <<loses << endl;
        cout << "Number of Wins: " << winnings << endl;
    }
}

void beginGame()
{
    cout << "Welcome to the Rock, Paper and Scissors Game!" <<endl;
    cout << "Let's begin. Type <rock, paper, scissors> for your choice!" <<endl;
    cin >> playerChoice;
    srand(time(0));
    int randomizer = 1+(rand()%3);
    if (randomizer == 1)
    comChoice = "rock";
    if (randomizer == 2)
    comChoice = "paper";
    if (randomizer == 3)
    comChoice = "scissors";

    do {
        if (playerChoice == comChoice)
        {
            drawGame();
        }

        if (playerChoice == "rock" && comChoice == "paper")
        {
            ++loses;
            lose();
        }

        if (playerChoice == "rock" && comChoice == "scissors")
        {
            ++winnings;
            winGame();
        }

        if (playerChoice == "paper" && comChoice == "rock")
        {
            ++winnings;
            winGame();
        }

        if (playerChoice == "paper" && comChoice == "scissors")
        {
            ++loses;
            lose();
        }

        if (playerChoice == "scissors" && comChoice == "rock")
        {
            ++loses;
            lose();
        }

        if (playerChoice == "scissors" && comChoice == "paper")
        {
            ++winnings;
            winGame();
        }


    } while (win != true);

}


int main ()
{
    beginGame();
    return 0;
}

There is still more stuff to fix, but I hope that helps. You should give more consideration to your questions however.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.