Program simulates the game of paper, rock, scissors

Assignment Help C/C++ Programming
Reference no: EM13945676

Please look through the code and debug and add anything into it. Make sure it says if the letter is invalid. I am an online learner. The book does not tell me everything. .

// ********************************************************************
//
// PaperRockScissors.cpp
//
// This program simulates the game of paper, rock, scissors. At
// each turn each player enters R, P, or S (either upper or lower
// case) to indicate their choice. The program announces the winner
// along with a message indicating the reason (such as Paper covers
// rock).
//
// ********************************************************************

#include <iostream>
using namespace std;

void printWelcome();
// Postcondition: A welcome and brief instructions are printed to the screen.
char CheckUserInput();

int main (int argc, char *argv[])
{
//
// Variable Declarations
//
char play1Choice, play2Choice;
char playAgain, charUserInput;

charUserInput = play1Choice, play2Choice;

//
// Print a welcome
//
printWelcome();

//
// Play the game as long as the users wish
//
do {

//
// Nested multiway if to determine the winner and update the score
//
cout << "Player 1 please press p for paper, s for scissor and r for rock.n";
cin >> play1Choice;

cout << "Player 2 please press p for paper, s for scissor and r for rock.n";
cin >> play2Choice;

if ((play1Choice == 'P')||(play1Choice == 'p'))
if ((play2Choice == 'P')||(play2Choice == 'p'))
{
cout << "Nobody wins.n";
cout << "Do you want to play again?: ";
cin >> playAgain;
}
else if ((play2Choice == 'S')||(play2Choice == 's'))
{
cout << "Player 2 wins. Scissors cut paper.n";
cout << "Do you want to play again?: ";
cin >> playAgain;
}
else
{
cout << "Player 1 wins. Paper covers rock.n";
cout << "Do you wan to play again?: ";
cin >> playAgain;
}
else if ((play1Choice == 'R')||(play1Choice == 'r'))
if ((play2Choice == 'R')||(play2Choice == 'r'))
{
cout << "Nobody wins.n";
cout << "Do you want to play again?: ";
cin >> playAgain;
}
else if ((play2Choice == 'P')||(play2Choice == 'p'))
{
cout << "Player 2 wins. Paper covers rock. n";
cout << "Do you want to play again?: ";
cin >> playAgain;
}
else
{
cout << "Player 1 wins. Rock breaks scissors.n";
cout << "Do you want to play again?: ";
cin >> playAgain;
}
else if ((play1Choice == 'S')||(play1Choice == 's'))
if ((play2Choice == 'S')||(play2Choice == 's'))
{
cout << "Nobody wins.n";
cout << "Do you want to play again?: ";
cin >> playAgain;
}
else if ((play2Choice == 'R')||(play2Choice == 'r'))
{
cout << "Player 2 wins. Rock breaks scissor.n";
cout << "Do you want to play again?: ";
cin >> playAgain;
}
else
{
cout << "Player 1 wins. Scissors cut paper.n";
cout << "Do you want to play again?: ";
cin >> playAgain;
}
}
while (playAgain == 'Y' || playAgain == 'y');

system("PAUSE");
return EXIT_SUCCESS;
}

void printWelcome()
{
cout << endl << endl;
cout << "Welcome to the Paper, Rock, Scissors Game!!!" << endl;
cout << "============================================" << endl;
cout << endl;
cout << "At each turn, both players enter a letter indicating";
cout << " their choice - " << endl;
cout << "P or p denotes Paper, R or r denotes Rock, S or s denotes Scissors."
<< endl << endl;
cout << "Start playing ... " << endl << endl;

}

char CheckUserInput(char charUserInput)
{
return(toupper(charUserInput)!='P'||'R'||'S')
return false;
else
return true;
}

Attachment:- Paper.zip

Reference no: EM13945676

Questions Cloud

Relationship between price and quantity demanded : The law of supply states that there is a direct relationship between price and quantity demanded. In the circular flow model, firms own economic resources, and householdsbuy the manufactured products and services
Why do systems analysts build models : How do they choose what to model, and which modeling techniques to use.
How many students do you expect will be unable to complete : Assume that the class has 60 students and that the examination period is 90 minutes in length. How many students do you expect will be unable to complete the exam in the allotted time?
Analyze the business environment and competition : Research Brief- Pick a company (Part 1) "Strategy means making clear-cut choices about how to compete. You cannot be everything to everybody, no matter what the size of your business or how deep its pockets." Jack Welch For this assignment you wil..
Program simulates the game of paper, rock, scissors : This program simulates the game of paper, rock, scissors. At each turn each player enters R, P, or S (either upper or lower case) to indicate their choice. The program announces the winner along with a message indicating the reason (such as Paper cov..
What is the advantage of using the normal probability : What is the advantage of using the normal probability distribution to approximate the binomial probabilities? Use part
Business brief that details your recommendation : Risk analysis is an essential practice in all business environments. What are the implications of option 1 versus option 2? Or even options 3, 4, and 5?! The key to risk analysis is to identify factors that have possible impact and assign a risk v..
Calculate the cost base of the land : Advise Alex whether the amount of $650,000 is ordinary income, assessable under s6-5 or whether any amount is assessable under s15-15 - calculate the cost base of (a) the land and (b) the house for Capital Gains Tax purposes. Explain what amounts a..
Sum of regenarate efficiency : Assume compressor and turbine efficiencies of 80% and 85%. A) find nth, T4a? B) what is nth if sum of regenarate efficiency is 80% installed?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Take the code you wrote for the ford-fulkerson algorithm

Take the code you wrote for the Ford-Fulkerson algorithm for the maximum flow on a directed graph with capacities, and implement scaling on top of this code. You write a function

  Write a program to track hourly employee arrival

A company hires you to write a program to track hourly employee arrival and departure times from work. In essence, you are tasked to make an online time clock - If the user enters an incorrect value more than 3 times, display a prompt that the prog..

  Create the program which converts fahrenheit to celsius

Create the following program which converts Fahrenheit to Celsius. Your program must have the following functions: Read integer Fahrenheit temperatures from the user.

  Computes the area of a rectangle

Create an object oriented application with C# that computes the area of a rectangle, and the area and the volume of a cuboid.

  Application to accept the name of a folder

Therefore, she asks Hayley to modify the application to accept the name of a folder and display the following details of the files located in the folder: File name File size File creation date. Write the code that Hayley should write to create the..

  Calculates the sum of the cube roots of two integers.

Wrtie a program that calculates the sum of the cube roots of two integers. The program should use the following functions as well as a main funcion. 1) enter one positive value 2) compute the cube root of one integer 3) report the value of two intege..

  What does the return statement do

What is the purpose of the function header?How may you identify the body of a function?  What does the return statement do?

  An arithmetic expression

The statements of that expression language consist of an arithmetic expression followed by a list of assignments. Assignments are separated from the expression and each other by commas. A semicolon terminates the expression. The arithmetic expr..

  Change unix file permission on unix

Modify selection_sort.c so that it includes the following functions:

  Develop a basic temperature class

You have to develop a basic temperature class

  Value referenced by the pointer.

Add 10 to the value referenced by pointer switch.Add 4 to the address stored in pointer switch.Subtract 5 from the value referenced by the pointer.

  Define the cheetah constructor to accept and initialize

Design and implement a class called Cheetah that contains instance data that represents the cheetah's name, age, weight, length and gender.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd