Created
May 1, 2012 20:53
-
-
Save kdmkdmkdm/2571301 to your computer and use it in GitHub Desktop.
slotmachine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // giSlotMachine.cpp : Defines the entry point for the console application. | |
| // | |
| #include "stdafx.h" | |
| #include <iostream> | |
| #include <cstdlib> | |
| #include <ctime> | |
| using namespace std; | |
| int Random(int low, int high); | |
| int main() | |
| { | |
| srand( time(0) ); | |
| int chipTotal = 1000; | |
| int oneOrTwo = 0; | |
| bool quit = false; | |
| while (!quit) | |
| { | |
| cout << "Player's chips: $" << chipTotal << endl; | |
| cout << "1) Play slot. 2) Exit. "; | |
| cin >> oneOrTwo; | |
| switch(oneOrTwo) | |
| { | |
| case 1: | |
| { | |
| int bet = 0; | |
| cout << "Enter your bet: "; | |
| cin >> bet; | |
| if (bet < 0 || bet > chipTotal) | |
| { | |
| cout << "You did not enter a valid bet." << endl; | |
| } | |
| else | |
| { | |
| int random1 = Random(2, 7); | |
| int random2 = Random(2, 7); | |
| int random3 = Random(2, 7); | |
| cout << random1 << " " << random2 << " " << random3 << endl; | |
| if (random1 == 7 && random2 == 7 && random3 == 7) | |
| { | |
| cout << "You Win!" << endl; | |
| chipTotal = chipTotal + bet * 10; | |
| } | |
| else if ((random1 == random2 == random3) && (random1 != 7)) | |
| { | |
| cout << "You Win!" << endl; | |
| chipTotal = chipTotal + bet * 5; | |
| } | |
| else if (random1 == random2 || random1 == random3 || random2 == random3) | |
| { | |
| cout << "You Win!" << endl; | |
| chipTotal = chipTotal + bet * 3; | |
| } | |
| else | |
| { | |
| cout << "You Lose!" << endl; | |
| chipTotal = chipTotal - bet; | |
| } | |
| break; | |
| } | |
| } | |
| case 2: | |
| { | |
| cout << "Exiting..." << endl; | |
| quit = true; | |
| break; | |
| } | |
| default: | |
| { | |
| cout << "Please choose 1 or 2." << endl; | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| int Random(int low, int high) | |
| { | |
| int randomNumber = low + rand() % (high - low); | |
| return randomNumber; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment