/* Program that lets the user play the game of Rock, Paper, Scissors against the computer. CRITERIA: • If one player chooses rock and the other player chooses scissors, then rock wins. (The rock smashes the scissors.) • If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts 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. */ #include<iostream> #include<iomanip> #include<conio.h> #include<cstdlib> #include<ctime> using namespace std; bool checkWin(int, int); int generateRand(); //For generating Random number between (0-4) int main() { int userCh, compCh; bool flag = 0; compCh = generateRand(); do { system("cls"); cout << setw(50) << "ROCK_PAPER_SCISSORS GAME\n"; //for formatting output for (int i = 0; i < 80; i++) cout << "~"; //For getting user input if (flag) cout << "\nEnter choice again:\n1=Rock\n2=Paper\n3=Scissors\n?"; else cout << "\nEnter your choice:\n1=Rock\n2=Paper\n3=Scissors\n?"; cin >> userCh; flag = 0; cout << "Computer's choice is \"" << compCh << "\"\n"; //Displays ComputerChoice //For formatting output for (int i = 0; i < 80; i++) cout << "=="; if (userCh != compCh) { //Displays result if (checkWin(userCh, compCh)) { cout << "\n" << setw(51) << "Congragulations!!!!!!!\n"; cout << setw(40) << "You Won\n"; } else { cout << "\n" << setw(48) << "OoOpPpsSs!!!!!!!\n"; cout << setw(45) << "Computer Won\n"; } } else { flag = 1; cout << "\nGame Draw.......\nPress any key to run again?"; _getch(); } } while (flag); return 0; } //Generats random number for computer choice int generateRand() { int value; srand(time(0)); do { value = rand(); } while (value < 1 || value>3); return value; } //For finding Winner bool checkWin(int userCh, int compCh) { if (userCh == 1 && compCh == 3 || userCh == 2 && compCh == 1 || userCh == 3 && compCh == 2 ) return 1; else return 0; }
y esa shit
ReplyDelete