Rock Paper Scissors code-Homework Help

Write your question here.
I need help with homework from my C++ programing class, in my class we are assigned to create a rock paper scissors program. These are the instructions:
Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows and be sure to divide the program into functions that perform each task. You must use the provided prototypes.

When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don't display the computer's choice yet). Write a function that returns the computers choice.

int computerChoice ();

The user enters his or her choice of 1 ("rock"), 2 ("paper"), or 3 ("scissors") at the keyboard. Write a function that returns the users choice.

int userChoice ();

The function should also keep asking for input until the user enters a valid choice: (sample output)

Choose rock=1, paper=2, scissors=3: 5

Choose rock=1, paper=2, scissors=3: 4

Choose rock=1, paper=2, scissors=3: -1

Choose rock=1, paper=2, scissors=3: 2

The computer's choice is displayed. Write a function that prints the computer's choice.

void printComputerChoice ( int computer_choice );

The function should print the following. (This is a sample output when the computer chose 3)

The computer chose 3

A winner is selected according to the following rules:
If one player chooses rock and the other player chooses scissors, then rock wins. (Rock smashes scissors).
If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cut paper).
If one player chooses paper and the other player chooses rock, then paper wins. (Paper wraps rock).
If both players make the same choice, the game must be played again to determine the winner.

Write a function to compute the winner. 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 );

Write a function to start a new game.

void playGame ()

The function should have the following outputs:
Example 1:

Choose rock=1, paper=2, scissors=3: 2

The computer chose 2

Choose rock=1, paper=2, scissors=3: 3

The computer chose 1

Computer Won!

Example 2:

Choose rock=1, paper=2, scissors=3: 1

The computer chose 3

User Won!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  Put the code you need help with here.
this is the code i have so far:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

// prototypes:
int computerChoice ();
int userChoice ();  
void  printComputerChoice ( int  computer_choice );
char  computeWinner ( int  computer_choice ,  int  user_choice ); 
void  playGame ();

// main:
int main () {


return 0;}

// functions:
int computerChoice () {
srand(time(NULL));
int choice=rand()%3+1;
return choice;}

int userChoice () {
int choice;
cout<<"Choose rock=1, paper=2, scissors=3:";
cin>>choice;
while (choice !=3&& choice !=2&& choice !=1){
cout<<"Choose rock=1, paper=2, scissors=3:";
cin>>choice;}
return choice;}

void  printComputerChoice ( int  computer_choice ) {
if (computer_choice==1)
{cout<<"Computer chose 1"<<endl;}
else if (computer_choice==2)
{cout<<"Computer chose 2"<<endl;}
else //if (computer_choice==3)
{cout<<"Computer chose 3"<<endl;}}

char  computeWinner ( int  computer_choice ,  int  user_choice ) {
if (user_choice==1&&computer_choice==2)
{cout<<"c"<<endl;}
if else (user_choice==2&&computer_choice==3)
{cout<<"c"<<endl;}
if else (user_choice==3&&computer_choice==1)
{cout<<"c"<<endl;}
if else (computer_choice==1&&user_choice==2)
{cout<<"u"<<endl;}
if else (computer_choice==2&&user_choice==3)
{cout<<"u"<<endl;}
if else (computer_choice==3&&user_choice==1)
{cout<<"u"<<endl;}
if else (computer_choice==user_choice)
{cout<<"t"<<endl;}
return 0; }

void  playGame () {
cout<<"Choose rock=1, paper=2, scissors=3: 2";
cout<<"The computer chose 2"; 
cout<<"Choose rock=1, paper=2, scissors=3: 3"; 
cout<<"The computer chose 1"; 
cout<<"Computer Won!"; 
What are you having trouble with?

Right now you're printing out the letter c,u or t and returning 0 in the computeWinner function, but it looks like they want you to return the c,u or t as a character to the calling function.
Write a function to compute the winner. The function should return 'u' if the user wins, 'c' if the computer wins, and 't' in the event of a tie.


You only have to seed the random function once at the beginning of the program, not every time you call the function.
srand(time(NULL));
may i know how i can make the program return c,u, or t?

can you also explain what i ought to do with the last part?
i also need help on completion of the code's final part
exactly what commands complete the code t bring hte result as mentioned in question 5?
Topic archived. No new replies allowed.