Purchase Solution

Debugging Code

Not what you're looking for?

Ask Custom Question

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;
}

Attachments
Purchase this Solution

Solution Preview

I made some changes for validating user input.

//

// ********************************************************************
//
// 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 "stdafx.h"
#include <iostream>
using namespace std;

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

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 ...

Purchase this Solution


Free BrainMass Quizzes
Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Basic Networking Questions

This quiz consists of some basic networking questions.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Javscript Basics

Quiz on basics of javascript programming language.