All pastes #169743 Raw Edit

Miscellany

public cpp v1 · immutable
·published 2006-09-14 04:51 UTC
rendered paste body
/****************Thomas BaillieCSE 231 (section 17)Project 3 - build date: 9/13/06*******************/#include <iostream>#include <string>				// used to manipulate/create values of type String#include <ctime>				// utilizes the system clock to seed for a semi-random numberusing namespace std;/* Begin variable declarations*/stringcompChoice(),				// this function reports the user's selectionuserChoice();				// this function reports the computer's selection//getPref();char choice;					// this char hold's the users input commands.void playGame();				// initializes the game routineint compWins = 0;				// the number of computer winsint userWins = 0;				// the number of user winsint scissorsCount = 0;			// the number of times the user chooses scissorsint	paperCount = 0;				// the number of times the user chooses paperint	rockCount = 0;				// the number of times the user chooses rockint tie = 0;					// the number of tiesint highest = 0;int main(){		cout << "Are you ready to play Rock, Paper, Scissors? Your choices are: \n\n";	cout << "   r/R for Rock\n";	cout << "   p/P for Paper\n";	cout << "   s/S for Scissors\n";	cout << "   q/Q to Quit\n\n";	cout << "Choose your weapon: ";	cin >> choice;				// show menu and take in initial user input	while (choice != 'Q' && choice != 'q'){		switch (choice){		// if the user doesn't quit, the program loops through this switch forever			case 's':			case 'S':			// if the user chooses scissors, add 1 to scissorsCount and then start the game				scissorsCount++;				playGame();				cout << "\nChoose your weapon (or q/Q to quit): ";				cin >> choice;				break;			case 'p':			case 'P':			// if the user chooses paper, add 1 to paperCount and then start the game				paperCount++;				playGame();				cout << "\nChoose your weapon (or q/Q to quit): ";				cin >> choice;				break;			case 'r':			case 'R':			// if the user chooses rock, add 1 to rockCount and then start the game				rockCount++;				playGame();				cout << "\nChoose your weapon (or q/Q to quit): ";				cin >> choice;				break;			default:			// if the user enters invalid input, force them to enter something valid				cout << "Invalid input! Please try again.\n\n";				cout << "Choose your weapon: ";				cin >> choice;				break;		}	}	// if the user enters q/Q, the above switch is bypassed and game scores are tallied up	cout << "\n\nYou've chosen to end the game.  The final results are:\n\n";	cout << "The computer won " << compWins << " times\n";	cout << "You won " << userWins << " times\n";	cout << "We tied " << tie << " times\n";	cout << "You selected Rock " << rockCount <<" times\n";	cout << "You selected Paper " << paperCount << " times\n";	cout << "You selected Scissors " << scissorsCount << " times\n\n";	cout << "Thanks for playing!\n\n";	system("pause");}	// end main()/*The playGame() function evaluates the data returned by the userChoice() and compChoice()functions to determine/output the winner of each round.*/void playGame(){	string userPref = "null";	cout << "\n\n[User Choice]: " << userChoice() << "\n";	cout << "[Computer Choice]: " << compChoice() << "\n";	if (userChoice() == "paper" && compChoice() == "rock"){		cout << "You win!\n\n";		userWins++;	}	else if (userChoice() == "scissors" && compChoice() == "paper"){		cout << "You win!\n\n";		userWins++;	}	else if (userChoice() == "rock" && compChoice() == "scissors"){		cout << "You win!\n\n";		userWins++;	}	else if (userChoice() == compChoice()){		cout << "You've tied!\n\n";		tie++;	}	else {		cout << "You lose!\n\n";		compWins++;	}	// GODDAMNIT, MAINTAIN THE ACTUAL CURRENT PREFERENCE, FUCK!	if (rockCount > scissorsCount || rockCount > paperCount){		highest = rockCount;		userPref = "rock";	}	else if (scissorsCount > rockCount || scissorsCount > paperCount){		highest = scissorsCount;		userPref = "scissors";	}	else if (paperCount > rockCount || paperCount > scissorsCount){		highest = paperCount;		userPref = "paper";	}	cout << "lol teh usarpreff: " << userPref;}// end playGame()/*The userChoice() function takes in the char value stored in choiceand returns the corresponding string value (rock/paper/scissors, respectively)*/string userChoice(){	string userChoice;	switch (choice){		case 'r':			userChoice = "rock";			break;		case 'p':			userChoice = "paper";			break;		case 's':			userChoice = "scissors";			break;		default:			userChoice = "null";			break;	}	return userChoice;}// end userChoice()/*compChoice() utilizes the srand() (which seeds the system clock) and rand() functions to generate a random number between 0-2 inclusive and designates 0,1,2 as rock,paper,scissors, respectively.*/string compChoice(){	int randVal = 0;	srand((unsigned)time(0)); 	randVal = rand()%3;	if (randVal == 0)		return "paper";	else if (randVal == 1)		return "rock";	else 		return "scissors";}//compChoice()