-3

I am having trouble with a Rock Paper Scissors game for school and I keep getting errors and I have no idea what to to do with them. Here is my code thus far.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <cctype>
#include <iostream>
using namespace std;

void playGame(int& pscore, int& cscore);
void getPlayerTurn (char selection);
int doComputerTurn (int comp);
void showOutcome (int result, int pturn, int cturn);

int main() {
    int pscore = 0;
    int cscore = 0;
    char answer;
    srand(time(0));
    cout << "*** Welcome to RPS ***" << endl;
    cout << endl;
    do {
            playGame(pscore, cscore);
            cout << "Play again? ";
            cin >> answer;
    } while(tolower(answer) == 'y');
            cout << "*** Thanks for playing ***" << endl;
}


void playGame(int& pscore, int& cscore) {

    int pturn = getPlayerTurn(int selection);
    int cturn = doComputerTurn(int comp);
     showOutcome(pscore, cscore, pturn);
    cout << "Player    : " << pscore << endl;
    cout << "Computer  : " << cscore << endl;
}

void getPlayerTurn(char selection) {
    cout << "Select (R)ock, (P)aper or (S)cissors: ";
    cin >> char selection;
    tolower(selection);
    char r = 1;
    char p = 2;
    char s = 3;
    return;
}

int doComputerTurn(int comp) {
     comp = rand() % 3 +1;
    if (comp == 1){
            cout << "Computer selects Rock." << endl;
            return(1);}
    else if (comp == 2){
            cout << "Computer selects Paper." << endl;
            return(2);}
    else{
            cout << "Computer selects Scissors." << endl;
            return(3);}
}

void showOutcome (int& pscore, int& cscore, int comp, int selection) {
    if(selection==1){
            if(comp==1){
                    cout << "Tie!" << endl;
                    }
            else if(comp==2){
                    cout << "Paper beats Rock. Computer Wins!" << endl;
                    cscore =+ 1;
                     }
            else {
                    cout << "Rock beats Scissors. Player Wins!" << endl;
                    pscore =+ 1;
                     }
                     }
    if(selection==2){
            if(comp==1){
                    cout << "Paper beats Rock. Player Wins!" << endl;
                    pscore =+ 1;
                     }
            else if(comp==2){
                    cout << "Tie!" << endl;
                    }
            else {
                    cout << "Scissors beats Paper. Computer Wins!" << endl;
                    cscore =+ 1;
                     }
                    }
    if(selection==3){
            if(comp==1){
                    cout << "Rock beats Paper. Computer Wins!" << endl;
                    cscore =+ 1;
                    }
            else if(comp==2){
                    cout << "Scissors beats Paper. Player Wins!" << endl;
                    pscore =+ 1;
                    }
            else {
                    cout << "Tie!" << endl;
                     }
}
}

I keep getting errors such as

rps.cpp: In function 'void playGame(int&, int&)':
rps.cpp:33:28: error: expected primary-expression before 'int'
int pturn = getPlayerTurn(int selection);
                        ^
rps.cpp:34:29: error: expected primary-expression before 'int'
int cturn = doComputerTurn(int comp);

Any help at all would be amazing!

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
Kardan
  • 3
  • 1
  • 3
    getPlayerTurn(int selection) => getPlayerTurn(selection). Don't mix up declaration with usage. You have a lot of other trivial syntax errors in your code. I think anyone with a small C/C++ background near you could help. – Jean-François Fabre Oct 09 '16 at 19:45
  • First off, this isn't neither C, nor C++,but a hard to read mixture of both. Then, you don't seem to distinguish between function _calls_ and _forward-declarations_. Googling these terms (or better buying a decent book about the C language) could help you. – ForceBru Oct 09 '16 at 19:47
  • it's C++, not C. There is a large difference between them, and far more than just one – quetzalcoatl Oct 09 '16 at 19:47
  • Learn more about [functions](http://www.learncpp.com/cpp-tutorial/14-a-first-look-at-functions/) and why not to use [using namespace std](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice;). – amanuel2 Oct 09 '16 at 19:51

1 Answers1

2

In C and C++, functions are declared like this:

void getPlayerTurn(int selection) {
    // Some code
}

The first part specifies the 'return type' (In this case void, indicating it returns nothing). The next part is the function name, followed by a list of parameters.

In a definition you have to indicate what type the parameter is, so in the code snippet above int selection indicates that the parameter selection is an int - an integer.

To call the function you don't need to declare the parameter type, because the compiler already knows what it is. So just call like this

getPlayerTurn(someVariable);
Ben Wainwright
  • 4,224
  • 1
  • 18
  • 36