Important alert: (current site time 10/20/2014 8:11:22 PM EDT)
 

VB icon

Rock Paper Scissors

Email
Submitted on: 3/9/2005 6:05:35 PM
By: Nathan Pfister 
Level: Beginner
User Rating: By 1 Users
Compatibility: C++ (general)
Views: 4598
(About the author)
 
     This is a simple game of rock paper scissors. It is one player with randomized computer play.

 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :Rock Paper Scissors
//**************************************
#include <iostream.h>
#include <math.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Rock Paper Scissors
// Description:This is a simple game of rock paper scissors. It is one player with randomized computer play.
// By: Nathan Pfister
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=9082&lngWId=3//for details.//**************************************

/****************************************************************************
 *Programmer: 	Nathan Pfister| .--._____, *
 *| .-='=='==-, " *
 *Program Name:	Rock Paper Scissors| (O_o_o_o_o_O)*
 *| *
 *----------------------------------------|---------------------------------*
 *Program Description: A simple game of rock paper scissors. Only one *
 *	player is allowed at the present time									*
 ****************************************************************************/
#include <iostream.h>
#include <math.h>
#define CSTDLIB;
#define CTIME;
using namespace std; 	
int main( void )
{
	int w = 0;				
	int t = 0;					
	int l = 0;
	char ST1[8];
	
	srand(time(NULL));
	
	cout<<"Welcome to Rock, Paper, Scissors!"<<endl;
	cout<<"On your turn you must input \"Rock\", \"Paper\", or \"Scissors\""<<endl<<"To quit simply type quit!";
	
	LabelA:
	cout<<endl<<endl<<endl<<"It's your turn! ";
	cin>>ST1;
	
	
	char ST2 = toupper(ST1[0]);
	
	for(w = 0;w <= 8;w++) 
		ST1[w] = toupper(ST1[w]);
	
	if (ST1[0] == 'R')
	{
		if (ST1[1] == 'O')
			goto LabelS;
		else
			goto LabelA;
	}
	if (ST1[0] == 'S')
	{
		if (ST1[1] == 'C')
			goto LabelS;
		else 
			goto LabelA;
	}
	if (ST1[0] == 'P')
	{
		if (ST1[1] == 'A')
			goto LabelS;
		else
			goto LabelA;
	}
	
	LabelS:
	switch(ST2)
	{
		case 'R':	
		{
			w = rand() % 3 + 1;
				if (w == 1)
				{
					cout<<"_______"<<endl<<"---'____)"<<endl<<" (_____)"<<endl<<" (_____)"<<endl<<" (____)"<<endl<<"---.__(___)"<<endl;
					cout<<"You played Rock!"<<endl;
					cout<<"_______"<<endl<<"---'____)"<<endl<<" (_____)"<<endl<<" (_____)"<<endl<<" (____)"<<endl<<"---.__(___)"<<endl;
					cout<<"Computer played Rock!"<<endl;
					cout<<"It's a tie!";
				}
				if (w == 2)
				{
					cout<<"_______"<<endl<<"---'____)"<<endl<<" (_____)"<<endl<<" (_____)"<<endl<<" (____)"<<endl<<"---.__(___)"<<endl;
					cout<<"You played Rock!"<<endl;
					cout<<"_____"<<endl<<"---'__)____"<<endl<<" ____)"<<endl<<"________)"<<endl<<" (____)"<<endl<<"---.__(___)"<<endl;
					cout<<"Computer played Scissors!"<<endl;
					cout<<"You win!";
				}
				if (w == 3)
				{
					cout<<"_______"<<endl<<"---'____)"<<endl<<" (_____)"<<endl<<" (_____)"<<endl<<" (____)"<<endl<<"---.__(___)"<<endl;
					cout<<"You played Rock!"<<endl;
					cout<<"_____"<<endl<<"---'__)____"<<endl<<"____)"<<endl<<" _____)"<<endl<<" _____)"<<endl<<"---.________)"<<endl;
					cout<<"Computer played Paper!"<<endl;
					cout<<"You lose!";
				}
				goto LabelA;
				break;
		}
		case 'S':
		{
			w = rand() % 3 + 1;
				if (w == 1)
				{
					cout<<"_____"<<endl<<"---'__)____"<<endl<<" ____)"<<endl<<"________)"<<endl<<" (____)"<<endl<<"---.__(___)"<<endl;
					cout<<"You played Scissors!"<<endl;
					cout<<"_______"<<endl<<"---'____)"<<endl<<" (_____)"<<endl<<" (_____)"<<endl<<" (____)"<<endl<<"---.__(___)"<<endl;
					cout<<"Computer played Rock!"<<endl;
					cout<<"You lost!";
				}
				if (w == 2)
				{
					cout<<"_____"<<endl<<"---'__)____"<<endl<<" ____)"<<endl<<"________)"<<endl<<" (____)"<<endl<<"---.__(___)"<<endl;
					cout<<"You played Scissors!"<<endl;
					cout<<"_____"<<endl<<"---'__)____"<<endl<<" ____)"<<endl<<"________)"<<endl<<" (____)"<<endl<<"---.__(___)"<<endl;
					cout<<"Computer played Scissors!"<<endl;
					cout<<"It's a tie!";
				}
				if (w == 3)
				{
					cout<<"_____"<<endl<<"---'__)____"<<endl<<" ____)"<<endl<<"________)"<<endl<<" (____)"<<endl<<"---.__(___)"<<endl;
					cout<<"You played Scissors!"<<endl;
					cout<<"_____"<<endl<<"---'__)____"<<endl<<"____)"<<endl<<" _____)"<<endl<<" _____)"<<endl<<"---.________)"<<endl;
					cout<<"Computer played Paper!"<<endl;
					cout<<"You win!";
				}
				goto LabelA;
				break;
		}
		case 'P':
		{
			w = rand() % 3 + 1;
				if (w == 1)
				{
					cout<<"_____"<<endl<<"---'__)____"<<endl<<"____)"<<endl<<" _____)"<<endl<<" _____)"<<endl<<"---.________)"<<endl;
					cout<<"You played Paper!"<<endl;
					cout<<"_______"<<endl<<"---'____)"<<endl<<" (_____)"<<endl<<" (_____)"<<endl<<" (____)"<<endl<<"---.__(___)"<<endl;
					cout<<"Computer played Rock!"<<endl;
					cout<<"You win!";
				}
				if (w == 2)
				{
					cout<<"_____"<<endl<<"---'__)____"<<endl<<"____)"<<endl<<" _____)"<<endl<<" _____)"<<endl<<"---.________)"<<endl;
					cout<<"_____"<<endl<<"---'__)____"<<endl<<" ____)"<<endl<<"________)"<<endl<<" (____)"<<endl<<"---.__(___)"<<endl;
					cout<<"Computer played Scissors!"<<endl;
					cout<<"You lose!";
				}	
				if (w == 3)
				{
					cout<<"_____"<<endl<<"---'__)____"<<endl<<"____)"<<endl<<" _____)"<<endl<<" _____)"<<endl<<"---.________)"<<endl;
					cout<<"You played Paper!"<<endl;
					cout<<"_____"<<endl<<"---'__)____"<<endl<<"____)"<<endl<<" _____)"<<endl<<" _____)"<<endl<<"---.________)"<<endl;
					cout<<"Computer played Paper!"<<endl;
					cout<<"It's a tie!";
				}
				goto LabelA;
				break;
		}
		case 'Q':
		{
			cout<<"Thank you for playing!"<<endl<<"This game brought to you by Nathan Pfister!";
			return 0;
		}
		goto LabelA;	
	}
	return 0;
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

3/14/2005 12:06:41 PMBrenton Andrew Saunders

Very original and very fun.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.