RPS

The same response is being chosen over and over again. How do I fix that?
mail@pastecode.io avatar
unknown
plain_text
a month ago
1.8 kB
4
Indexable
Never
#include <iostream>
#include <cstdlib>
#include <ctime>

int main(){


	char r = 'r';
	char p = 'p';
	char s = 's';
	char guess = 0;
	int comGuess = 1 + std::rand() / ((RAND_MAX + 1u) / 3);
	int comRock = 1;
	int comPaper = 2;
	int comScissors = 3;

	std::srand(static_cast<unsigned int>(std::time(nullptr)));

	std::cout << " ROCK PAPER SCISSORS \n********************* \n";
	std::cout << "Rules are simple!";

	while (guess != r && guess != p && guess != s) {
		std::cout << "\nType 'r' to select Rock!";
		std::cout << "\nType 'p' to select Paper!";
		std::cout << "\nType 's' to select Scissors!";
		std::cout << "\nGuess: ";
		std::cin >> guess;
	}

	if (guess == r && comGuess == comRock) {
		std::cout << "\nPlayer chose ROCK! Computer chose ROCK! It's a tie!";
	}
	else if (guess == r && comGuess == comPaper){
		std::cout << "\nPlayer chose ROCK! Computer chose PAPER! Computer WINS!";
	}
	else if (guess == r && comGuess == comScissors) {
		std::cout << "\nPlayer chose ROCK! Computer chose SCISSORS! Player WINS!";
	}
	else if (guess == p && comGuess == comRock) {
		std::cout << "\nPlayer chose PAPER! Computer chose ROCK! Player WINS!";
	}
	else if (guess == p && comGuess == comPaper) {
		std::cout << "\nPlayer chose PAPER! Computer chose PAPER! It's a tie!";
	}
	else if (guess == p && comGuess == comScissors) {
		std::cout << "\nPlayer chose PAPER! Computer chose SCISSORS! Computer WINS!";
	}
	else if (guess == s && comGuess == comRock) {
		std::cout << "\nPlayer chose SCISSORS! Computer chose ROCK! Computer WINS!";
	}
	else if (guess == s && comGuess == comPaper) {
		std::cout << "\nPlayer chose SCISSORS! Computer chose PAPER! Player WINS!";
	}
	else if (guess == s && comGuess == comScissors) {
		std::cout << "\nPlayer chose SCISSORS! Computer chose SCISSORS! It's a tie!";
	}
	
		
	return 0;
}
Leave a Comment