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;
}
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?
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/