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 103 104 105 106 107 108 109 110
|
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
char play;
int guess;
bool done;
int noOfGuesses = 0;
int random;
int c;
double bank, winnings, total;
int check;
void printPayout()
{
cout << "1 guess, win 2.00" << endl;
cout << "2 guesses, win 1.75" << endl;
cout << "3 guesses, win 1.5" << endl;
cout << "4 guesses, win 1.25" << endl;
cout << "5 guesses, win 1.00" << endl;
cout << "6 guesses, .75" << endl;
cout << "7 guesses, win .5" << endl;
cout << "8 guesses, win .25" << endl << endl;
}
int checkGuess(int guess)
{
if (guess > random)
{
check = 1;
}
else if (guess < random)
{
check = -1;
}
else
{
check = 0;
}
return (check);
}
int genRandom()
{
int r;
srand(time(NULL));
r = rand() % 100 + 1;
return r;
}
int game()
{
cout << "Welcome to the guess-o-matic. It only costs a dollar to play. You could double your bet." << endl << endl;
cout << "Do you want to play (y / n)" << endl;
bank = 100.00;
cin >> play;
if (play=='y')
{
winnings = 2.00;
cout << "Great!, your payout will be as follows:" << endl << endl;
printPayout();
random = genRandom();
while((bank!=0)&&(play=='y'))
{
noOfGuesses=0;
random = genRandom();
winnings = 2.00;
while ((noOfGuesses!=8))
{
cout << "Now guess a number between 1 and 100" << endl;
cin >> guess;
noOfGuesses++;
c = checkGuess (guess);
if (c == 0)
{
bank = bank + winnings;
cout << "Correct, you win " << winnings << ", your bank is now "<< bank<< endl<<"Do You Wanna Play Again??(Y/N)";
cin>>play;
break;
}
else if (c == -1)
{
cout << "Sorry too low try higher" << endl;
winnings = winnings - .25;
}
else if (c == 1){
cout << "Sorry too high try lower" << endl;
winnings = winnings - .25;
}
}
}
}
cout<<"Thank You For Playing, you are left with a total of " <<bank<<" $\n Wishing you will be back to play once more.";
return 0;
}
int main()
{
game();
return 0;
}
|