1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;
//Prototypes
int menu(int &UserMoney, int &OptionSelect, int ErrorCheck, int betting);
int HighLow(int &UserMoney, int HighLowGuess, int ErrorCheck, int betting);
void Roulette();
void Blackjack();
void SetBetting();
int main()
{
srand(time(NULL));
int UserMoney = (rand() % 100) + 100;
int OptionSelect = 0;
int ErrorCheck = 0;
// betting variables
int betting = 5;
//game variables
int HighLowGuess;
menu(UserMoney, OptionSelect, ErrorCheck, betting);
cout << OptionSelect << endl; //to test for optionselect being modified in menu
/* switch(OptionSelect)
{
case 1:
HighLow(UserMoney, HighLowGuess, ErrorCheck, betting);
}
*/
/* if(OptionSelect == 1) //called OptionSelect is not activating the if statement
{
HighLow(UserMoney, HighLowGuess, ErrorCheck, betting);
} */
}
int menu(int &UserMoney, int &OptionSelect, int ErrorCheck, int betting)
{
cout << "You have $" << UserMoney << "." << endl;
//Loop for error in input
// while(ErrorCheck == 0)
//Option Select
cout << "What would you like to do (Enter 1-5)" << endl;
cout << "1) Play High-Low" << endl << "2) Play Roulette" << endl << "3) Play 21" << endl << "4) Set Betting Amount" << endl << "5) Exit" << endl;
cin >> OptionSelect;
//check to be sure input is a number
if((!(OptionSelect > 0)) || (OptionSelect > 5) )
{
cout << "Please Only Enter a Number Between 1 and 5." << endl;
}
else
{
ErrorCheck = ErrorCheck + 1;
}
// }
}
int HighLow(int &UserMoney, int HighLowGuess, int ErrorCheck, int betting)
{
while (ErrorCheck = 0)
{
int RandNum1 = (rand() % 10) + 1;
cout << "The number is " << RandNum1 << "." << endl << "Will the next number be higher or lower (1 or 2)?" << endl << "1) Higher" << endl << "2)Lower" << endl;
cin >> HighLowGuess;
int RandNum2 = (rand() % 10) + 1;
if ((HighLowGuess = 1) && (RandNum1 < RandNum2) )
{
UserMoney = UserMoney + (betting * 1);
cout << "The next number was " << RandNum2 << "." << endl << "Congratulations! You got it right." << endl;
cout << "Your new balance is $" << UserMoney << "." << endl;
}
else if ((HighLowGuess = 2) && (RandNum1 > RandNum2) )
{
UserMoney = UserMoney + (betting * 1);
cout << "The next number was " << RandNum2 << "." << endl << "Congratulations! You got it right." << endl;
cout << "Your new balance is $" << UserMoney << "." << endl;
}
else
{
cout << "Error: Please only enter either 1 or 2." << endl;
}
}
}
|