Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int displaystats(int gamesplayed, int wins, int losses, int bank);
- int main()
- {
- int bank = 100;//intital bank value
- int bet = 0;//desired wager
- int wins = 0;//games won
- int losses = 0;//games lost
- int gamesplayed = 0;//how many rounds you played
- int compdice1 = 0;//first rolled dice for computer
- int compdice2 = 0;//second rolled dice for computer
- int playdice1 = 0;//first rolled dice for player
- int playdice2 = 0;//seconds rolled dice for player
- int newdice = 0;//the dice to risk your wager
- int comproll = 0;//the sum of the computers roll
- int playroll = 0;//the sum of the players roll
- do
- {
- if (bank < 0)
- {
- cout << "You have " << bank << " coins in your bank." << endl;
- cout << "I am sorry you are out of money." << endl;
- displaystats(gamesplayed, wins, losses, bank);
- break;
- }
- else if (bank > 0)
- {
- cout << "You have " << bank << " coins in your bank." << endl;
- cout << "How many coins would you like to bet? ";
- cin >> bet;
- //This is the line that you forgot.
- bank = bank - bet;
- compdice1 = (rand() + time(0)) % 6 + 1;//computer dice
- compdice2 = (rand() + time(0)) % 6 + 1;//computer second dice
- playdice1 = (rand() + time(0)) % 6 + 1;//player dice
- playdice2 = (rand() + time(0)) % 6 + 1;//player second dice
- comproll = compdice1 + compdice2;//computer sum
- playroll = playdice1 + playdice2;//player sume
- cout << "Your roll was " << playdice1 << " and " << playdice2 << " with a sume of " << playroll << endl;
- if (playroll < comproll)
- {
- char option;//option to roll another dice
- cout << "You win!" << endl;
- cout << "Would you like to roll a third dice to earn 1.5 times your bet, yes or no? ";
- cin >> option;
- if (option == 'yes')
- {
- int newroll;//the new sum of the three dice
- int newdice;//the extra roll
- newdice = (rand() + time(0)) % 6 + 1;
- newroll = playroll + newdice;//the value of players roll
- if (newroll > comproll)
- {
- cout << "The computer rolled " << comproll << endl;
- cout << "You now rolled higher than the computer therefore, I am sorry you lose this round." << endl;
- cout << "Your bank now equals " << bank - bet << endl;
- losses++;
- gamesplayed++;
- }
- else if (newroll < comproll)
- {
- cout << "You win!" << endl;
- cout << "Your bank now equals " << bank + (1.5 * bet) << endl;
- wins++;
- gamesplayed++;
- }
- }
- else if (option == 'no')
- {
- cout << "Your bank now equals " << bank + bet << endl;
- wins++;
- gamesplayed++;
- }
- }
- else if (playroll > comproll)
- {
- cout << "The computer rolled " << comproll << endl;
- cout << "You rolled higher than the computer therefore, I am sorry you lose this round." << endl;
- cout << "Your bank now equals " << bank - bet << endl;
- losses++;
- gamesplayed++;
- }
- else if (playroll = comproll)
- {
- cout << "The computer also rolled " << comproll << endl;
- cout << "I am sorry you now lose double your bet!" << endl;
- cout << "Your bank now equals " << bank - (2 * bet) << endl;
- losses++;
- gamesplayed++;
- }
- }
- } while (bank > 0);
- int stats = displaystats(gamesplayed, wins, losses, bank);
- cout << "Your stats are " << stats << endl;
- return 0;
- }
- int displaystats(int gamesplayed, int wins, int losses, int bank)
- {
- cout << "Games Played: " << gamesplayed << endl;
- cout << "Wins: " << wins << endl;
- cout << "Losses: " << losses << endl;
- cout << "Bank Total: " << bank << endl;
- return (gamesplayed, wins, losses, bank);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement