rock paper scissors help

Hi,
This is my first time on this forum so I want to thank you in advance for your help. When I submitted this program, i got the following error:

8.1: expected unqualified-id before '{' token
{
^
I tried fixing this in many ways to match the requirements given with no results.

I was also asked the following:
1. Write a function that returns the computers choice.
int computerChoice ();
2. Write a function that returns the users choice.
int userChoice ();
3. Write a function that prints the computer's choice.
void printComputerChoice ( int computer_choice );
4. The function should return 'u' if the user wins, 'c' if the computer wins, and 't' in the event of a tie.
char computeWinner ( int computer_choice , int user_choice );
5. Write a function to start a new game.
void playGame ()


Your help is greatly appreciated.

//Play a game of rock, paper, scissors vs computer
#include<iostream>
#include<cmath>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
{
int computerChoice(){
int computerChoice = (rand()%3)+1;
return computerChoice;
}
int userChoice;{
cin>>userChoice;
return userChoice;
}

while(userChoice!=1 && userChoice!=2 && userChoice!=3){
cout<<"Chose rock=1, paper=2, scissors=3:"<<endl;
cin>>userChoice;
}

while(userChoice ==computerChoice){
cout<<'t'<<endl;
cout<<"The computer chose "<<computerChoice<<endl;
cout<<"Chose rock=1, paper=2, scissors=3:"<<endl;
computerChoice = (rand()%3)+1;
cin>>userChoice;
}
void printComputerChoice( int computer_choice );
void playGame ();
if(userChoice==1){
if(computerChoice==2){
cout<<'c'<<endl;
cout<<"The computer chose "<<computerChoice<<endl;
cout<<"Computer Won!"<<endl;}
if(computerChoice==3){
cout<<'u'<<endl;
cout<<"The computer chose "<<computerChoice<<endl;
cout<<"User Won!"<<endl;}
}
if(userChoice==2){
if(computerChoice==1){
cout<<'u'<<endl;
cout<<"The computer chose "<<computerChoice<<endl;
cout<<"User Won!"<<endl;}

if(computerChoice==3){
cout<<'c'<<endl;
cout<<"The computer chose "<<computerChoice<<endl;
cout<<"Computer Won!"<<endl;}
}
if(userChoice==3){
if(computerChoice==1){
cout<<'c'<<endl;
cout<<"The computer chose "<<computerChoice<<endl;
cout<<"Computer Won!"<<endl;}
if(computerChoice==2){
cout<<'u'<<endl;
cout<<"The computer chose "<<computerChoice<<endl;
cout<<"User Won!"<<endl;}
}
}

int main(){
srand(time(NULL));

playGame();

return 0;
}
void playGame ();

The semicolon ends the playGame function right there. You don't need a semicolon when you're actually defining the function.
1
2
3
4
5
return type function name(parameters)
{
function statements;
return something if not a void function;
}



If userchoice and computerchoice are functions you are calling here, you need userChoice() and computerChoice(), otherwise they look like undeclared variables.

1
2
if(userChoice==1){
if(computerChoice==2){



These while loops appear to be outside of any function. Where do you mean to run these?
1
2
while(userChoice!=1 && userChoice!=2 && userChoice!=3)
while(userChoice ==computerChoice)



Edit: You can use code tags on the forum to make your code easier to read. :) There's a button with <> on it in the format tools at the right side of the post.
http://www.cplusplus.com/articles/jEywvCM9/
Last edited on
Thanks, I will try the suggestions and update. Your help is appreciated.
Guys, I appreciate the help. The program now work the way it was intended to.
Topic archived. No new replies allowed.