0% found this document useful (0 votes)
49 views

Coding Example

Uploaded by

api-317254126
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Coding Example

Uploaded by

api-317254126
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

//

//
//
//
//
//
//

main.cpp
assignment1
Created by Stephen Addison on 10/15/15.
Copyright 2015 Stephen Addison. All rights reserved.

#include <iostream>
using namespace std;
int showMenu();
void rockPaperscissors();
void rollDice();
int main()
{
void rockPaperscissors(), rollDice();
int choice;
choice = showMenu();
if (choice == 1)
rockPaperscissors();
else if (choice == 2)
rollDice();
else
cout << "Game Ending!" << endl;
return 0;
}
int showMenu()
{
int choice;
cout << "1. Play Rock/Paper/Sciccorss." << endl;
cout << "2. Play Dice Role Game." << endl;
cout << "3. Exit (if any other input)" << endl;
cout << "Enter your choice: " << endl;
cin >> choice;
return choice;
}
void rockPapersciccors()
{
int answer, computer;
cout << "1. Rock " << endl;
cout << "2. Paper " << endl;

cout << "3. Scissors " << endl;


cout << "Choose Rock, Paper or Scissor (1-3)" << endl;
cout << "Enter your choice: " << endl;
cin >> answer;
computer = 1 + rand() % 3;
switch (answer)
{
case 1:
if ( computer == 3 && answer == 1 )
cout << "Rock beats Scissors"<< endl;
else if (computer == 2 && answer == 1)
cout << "Paper beats Rock"<< endl;
else
cout << "Rock ties Rock" << endl;
break;
case 2:
if (computer == 2 && answer == 1)
cout << "Paper beats Rock" << endl;
else if (computer == 2 && answer == 3)
cout << "Scissors beats paper" << endl;
else
cout << "Scissors ties Scissors" << endl;
break;
case 3:
if (computer == 3 && answer == 2)
cout << "Scissors beats paper" << endl;
else if (computer == 3 && answer == 1)
cout << "Rock beats Scissors" << endl;
else
cout << "Scissors ties Scissors" << endl;
break;
default: cout << "Invalid Choice" <<endl;
}
}
void rollDice()
{
int dice1,dice2, dicetotal,decision;
dice1 = 1 + rand() % 6;
dice2 = 1 + rand() % 6;
cout << "1. Roll only one dice" << endl;
cout << "2. Ronly two dice"<< endl;
cout << " Enter your choice" << endl;

cin >> decision;


if(decision == 1)
{
cout << "The dice 1 displays" << dice1 << endl;
if (dice1 == 4)
{ cout << "Yout get three points " << endl;
}
}
if (decision == 2)
cout << "The dice 1 displays" << dice1 << endl;
cout << "The dice 2 displays" << dice2 << endl;
dicetotal = dice1 + dice2;
if(dicetotal == 7)
cout << "You get 10 points"<< endl;
else if (dice1 == dice2)
cout << "You get 5 points" << endl;
else if (dice1 == 4 || dice2 == 4)
cout << "You get three points" << endl;
else
cout << "No points" << endl;

You might also like