non
non

Reputation: 11

Program not compiling due to error in the value returning function. It says undeclared identifier

I'm coding a program for rock paper scissors where there is a user player and a computer player. I believe everything is fine up to the bool value returning function. It needs to take two arguments (computer's choice, player's choice) and see if they are equal to print out "Tie". However, I'm getting an error that says undeclared identifiers for my two arguments.

I tried changing it to an int function instead of bool. and have my bool statements in main, but it did not work

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

 using namespace std;

int getComputerChoice();
int getPlayerChoice();
bool isTie (int, int);

 int main()
  {

char choice;
int compChoice;
int plaChoice;


do
{
    cout << "ROCK PAPER SCISSORS MENU" << endl;
    cout << "--------------------------" << endl;
    cout << "p)Play Game" << endl;
    cout << "q)Quit" << endl;
    cout << "Please enter your choice : " << endl;
    cin >> choice;


    while (choice != 'p' && choice != 'q')//or if//why &&
    {
        cout << "Invalid selection. Try again." << endl << endl << endl;
        cin >> choice;
    }

    switch (choice)
    {
    case 'p':
        compChoice = getComputerChoice();

        plaChoice = getPlayerChoice();

        if (plaChoice == 1)
        {
            cout << "You chose: Rock" << endl;
        }
        else if (plaChoice == 2)
        {
            cout << "You chose: Paper" << endl;
        }
        else 
        {
            cout << "You chose: Scissors" << endl;
        }


        if (compChoice == 1)
        {
            cout << "The computer chose: Rock" << endl;
        }
        else if (compChoice == 2)
        {
            cout << "The computer chose: Paper" << endl;
        }
        else
        {
            cout << "The computer chose: Scissors" << endl;
        }


        if (isTie(compChoice, plaChoice))
        {
            cout << "It is a Tie!";
        }



        break;


    case 'q':
        cout << "You have chosen to quit the program. Thank you for using the program!" << endl;
        break;

    }

} while (choice != 'q');


 return 0;
}



  int getComputerChoice()
   {
int comp = 0;
int rando = 0;
srand((unsigned int)time(NULL));

rando = rand() % 3 + 1;

switch (rando)
{
case 1:
     comp = 1;
    break;

case 2:
    comp = 2;
    break;

case 3:
    comp= 3;
    break;

    return comp;
}
  }


   int getPlayerChoice()
  {

int player;
cout << "Rock, Paper or Scissors?" << endl;
cout << "1) Rock" << endl;
cout << "2) Paper" << endl;
cout << "3) Scissors" << endl;
cout << "Please enter your choice: " << endl;
cin >> player;

while (player != 1 && player != 2 && player != 3)
{
    cout << "Invalid" << endl;
    cin >> player;
}
return player;
    }

  bool isTie(compu, playa)
   {
if (compu == playa)
    return true;
else
    return false;

     }

These are the error messages I'm getting compu': undeclared identifier playa': undeclared identifier 'isTie': redefinition; previous definition was 'function' see declaration of 'isTie' 'isTie': function-style initializer appears to be a function definition

Upvotes: 0

Views: 59

Answers (1)

EylM
EylM

Reputation: 6103

isTie is a function that has 2 parameters. From your code, I can see that it's expecting 2 integers.

So you need to update the function signature to:

bool isTie(int compu, int playa)

Upvotes: 1

Related Questions