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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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