Switch function

play my game and type in "aaaaar" for your choice. Why does

Page 1 of 1

3 Replies - 3105 Views - Last Post: 27 August 2008 - 09:20 PM Rate Topic: -----

#1 kellymart  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 05-October 07

Switch function

Posted 05 December 2007 - 08:51 PM

#include <iostream>
#include <ctime>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <windows.h>

using namespace std;

enum Choice { Rock, Paper, Scissors }; // Rock=r, Paper=p, Scissors=s
enum Decision { Draw, Win, Lose }; // Draw=0, Win=1, Lose=2
string bal;
char DoMenu();
void CheckWinner(int PlayerChoice);

int main()
{  
	//  initialize the computer's random number generator
	srand(time(0));
	   
	//  declare variables
	char choice;
cout << "\n\n";	
cout << "\\\\\\\\\\\\\***Welcome to Rock Paper Scissors Game***////////\n\n";
cout << "Enter your choice to begin game!!\n";
cout << "\n\n";
	do
	{
		choice = DoMenu();

		switch (choice)
		{
			  
			case 'R': break; // fall through
			case 'r': cout << "\nPlayer: Rock\n"; CheckWinner(Rock); break;
			case 'P': break;// fall through
			case 'p': cout << "\nPlayer: Paper\n"; CheckWinner(Paper); break;
			case 'S': break;// fall through
			case 's': cout << "\nPlayer: Scissors\n"; CheckWinner(Scissors); break;
			default : cout << "\n"; break;
			
		}

	} while ((choice != 'Q') && (choice != 'q'));
cout <<"\n\n";
cout <<"Thanks for playing!!!!\n";

Sleep(3000);
	// end program 
	return 0; 
}

char DoMenu()
{
	char MenuChoice;
		cout << "(R)ock\n";
		cout << "(P)aper\n";
		cout << "(S)cissors\n";
		cout << "(Q)uit\n";
		cout << "----------\n";
		cout << "Choice: ";
		cin >> MenuChoice;
		system("cls");
		return MenuChoice;
	
}

void CheckWinner(int PlayerChoice)
{
	int random = rand()%3;

	switch (random)
	{
		   
		case Rock:	 cout << "Computer: Rock\n";	   break;
		case Paper:	cout << "Computer: Paper\n";	break;
		case Scissors: cout << "Computer: Scissors\n"; break;
	}

	Decision outcome;

	if (PlayerChoice == Rock)
	{
		switch (random)
		{
			case Rock:	   outcome = Draw; break;
			case Paper:	outcome = Lose; break;
			case Scissors: outcome = Win;  break;
		}
	}

	if (PlayerChoice == Paper)
	{
		switch (random)
		{
			case Rock:	   outcome = Win;  break;
			case Paper:	outcome = Draw; break;
			case Scissors: outcome = Lose; break;
		}
	}

	if (PlayerChoice == Scissors)
	{
		switch (random)
		{
			case Rock:	   outcome = Lose; break;
			case Paper:	outcome = Win;  break;
			case Scissors: outcome = Draw; break;
		}
	}

	switch (outcome)
	{
					  
		case Win:  cout << "Player Wins!\n\n\a\a\a\a\a\a\a\a\a\a";   break;
		case Lose: cout << "Computer Wins!\n\n\a\a\a"; break;
		case Draw: cout << "Draw\n\n";			 break;
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Switch function

#2 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Switch function

Posted 05 December 2007 - 09:25 PM

Okay...what are you trying to achieve with this code?
Was This Post Helpful? 0
  • +
  • -

#3 keungsuh23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-August 08

Re: Switch function

Posted 27 August 2008 - 08:48 AM

i dont get it!!! lol

This post has been edited by keungsuh23: 27 August 2008 - 09:59 AM

Was This Post Helpful? 0
  • +
  • -

#4 TheRofl  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 13-August 08

Re: Switch function

Posted 27 August 2008 - 09:20 PM

It would help if you explain your problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1