the requirements for this assignment are to use enums and functions and an option to play again. im pretty confuse on exactly what I am doing wrong. also extremely new to programing
here what I got any help is great
using namespace std;
// enums
enum Option {rock = 'R', paper = 'P', scissors = 'S'};
//functions
void displayInstrutions ()
{
cout << "Lets play rock, paper, scissor against the computer" <<endl;
cout << "Rock beats scissors, scissors beats paper and paper beats rock" <<endl;
}
Some formatting & indentation would not hurt either
You should call srand ONE TIME ONLY, not every time you enter getCompMove. You are potentially reseeding the C random generator multiple times before time has a chance to tick to the next time interval, effectively resetting the random generator to the beginning of the same sequence.
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
// enums
enum Option { rock = 'R', paper = 'P', scissors = 'S' };
//functions
void displayInstrutions() {
cout << "Lets play rock, paper, scissor against the computer" << endl;
cout << "Rock beats scissors, scissors beats paper and paper beats rock" << endl;
}
string getMove() {
int move;
cout << "\nChoices:" << endl;
cout << "R - Rock" << endl;
cout << "P - Paper " << endl;
cout << "S - Scissors " << endl;
cout << "Enter your choice: " << endl;
cin >> move;
move = tolower(move);
if (move == rock) {
cout << "you choose rock" << endl;
} elseif (move == scissors) {
cout << "you choose scissors" << endl;
} elseif (move == paper) {
cout << "you choose paper" << endl;
} else {
cout << "invalid entry" << endl;
}
return {};
}
int getCompMove() {
srand(time(0));
constint MAX_VALUE = 3;
constint MIN_VALUE = 1;
auto c_move = (rand() % MAX_VALUE - MIN_VALUE + 1) + MIN_VALUE;
if (c_move == 1) {
c_move = rock;
}
if (c_move == 2) {
c_move = paper;
}
if (c_move == 3) {
c_move = scissors;
}
return c_move;
}
bool getWinner(int c_move, int userMove) {
if ((userMove == rock) && (c_move == 3)) {
returntrue;
} elseif ((userMove == rock) && (c_move == 2)) {
returnfalse;
} elseif ((userMove == scissors) && (c_move == 2)) {
returntrue;
} elseif ((userMove == scissors) && (c_move == 1)) {
returnfalse;
} elseif ((userMove == paper) && (c_move == 1)) {
returntrue;
} elseif (userMove == paper && c_move == 3) {
returnfalse;
} elseif (userMove == c_move) {
return"its a tie";
} else {
cout << "Invalid entry" << endl;
}
returnfalse;
}
bool playAgain(int playAnswer) {
constchar yes = 'Y';
constchar no = 'N';
int answer;
do {
cin >> answer;
answer = tolower(answer);
if (answer != yes && answer != no) {
cout << "invalid entry" << endl;
}
answer = playAnswer;
} while (answer != yes && answer != no);
}
int main() {
//variables
int compMove = 0;
int userMove = 0;
cout << "Wanna play a game?" << endl;
displayInstrutions();
//user choice / function
getMove();
getCompMove();
//winner
cout << "The winner is: " << endl;
getWinner
cout << "would you like to play again? Y or N " << endl;
playAgain(bool)
}
L37. Shouldn't you return the move choice?
L41 - as stated above, this should be moved to the beginning of main().
getWinner() - there's no need to have an else statement after a return.
playAgain() - the function needs to return a value. Why is a function argument needed?
L112 - the returned value from the function is not used.
L113 - the returned value from the function is not used.
L117 - This needs to be called with 2 parameters - as per the function definition - and a terminating ; is needed.
L120 - This needs to be called as per its definition and a terminating ; is needed.