-
rock paper Scissors
i'm supposed to do a rock paper scissors program for my class and here's how my teacher wants it to look like.
Your choice: R)ock, S)cissors, P)aper, or Q)uit: x
Please enter R for rock, S for scissors, P for paper, or Q to quit: s
Computer chose Paper - you win.
Your choice: R)ock, S)cissors, P)aper, or Q)uit: p
Computer chose Scissors - you lose.
Your choice: R)ock, S)cissors, P)aper, or Q)uit: R
Computer chose Rock - it's a draw.
Your choice: R)ock, S)cissors, P)aper, or Q)uit: R
Computer chose Scissors - you win.
Your choice: R)ock, S)cissors, P)aper, or Q)uit: Q
Your wins: 2
Computer's wins: 1
Number of draws: 1
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
// These includes let us work with vectors:
#include <vector>
#include <algorithm>
// This include lets us read and write files:
#include <fstream>
using namespace std;
/*
This is a global type -- it is defined outside
of a function, so it is available to *all* functions
*/
enum winnerType = {PLAYER, COMPUTER, DRAW};
int main()
{
winnerType winner;
// declare variables
giveDirections( )
playerChoice = getPlayerInput( )
while (playerChoice != 'Q')
{
computerChoice = getComputerChoice( );
winner = determineWinner( playerChoice,
computerChoice );
if (winner == PLAYER)
{
playerWins++;
display congratulations
}
else if (winner == COMPUTER)
{
computerWins++;
cout << "Sorry you lost this one" << endl;
}
else
{
draws++;
}
totalGames++;
player makes choice again
}
display playerWins
display computerWins
display draws
display totalGames
system("PAUSE");
return 0;
}
void giveDirections( )
{
// you figure this one out
}
/*
do
{
input a character
convert to upper case
if (character != R or S or P or Q)
{
give an error message
}
} while (character != R or S or P or Q);
return character
[note: "or" is English; you will need && in C++]
*/
char getPlayerInput( )
{
}
/*
char choice = ' ';
set r to a random number from 0..2
switch (r)
{
0: choice = 'R'
1: choice = 'S'
2: choice = 'P'
}
return choice
*/
char getComputerChoice( )
{
}
/*
winnerType theWinner;
if (player == computer)
{
theWinner = DRAW;
}
else if ( player=='R'/computer=='S' OR/AND???
player=='S'/computer=='P' OR/AND???
player=='P'/computer=='R')
{
theWinner = PLAYER;
}
else
{
theWinner = COMPUTER;
}
return theWinner;
*/
winnerType determineWinner( char player, char computer )
{
}
-
Yes, and your question is ... ?
-
Code:
// you figure this one out
Sounds good to me. If you actually have a question, I suppose you could ask.
-
Ha thats sad... its practically handed to you. Perhaps the question you should ask is: Why am I taking this class?