Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include "coin.h"
- using namespace std;
- int main()
- {
- Coin quarter;
- Coin dime;
- Coin nickel;
- double balance = 0;
- cout << "Welcome to the coin game!\nThere are three coins: a quarter, a dime, and a nickel.\nEach round the coins will be flipped.\nIf any of the coins land on heads that will be added to your balance.\nIf you end a round with exactly $1.00 you win the game!\n\n";
- while (balance < 1.00)
- {
- system("pause");
- cout << endl;
- double wonThisRound = 0;
- cout << "Start of Round:\n";
- quarter.toss();
- cout << "The quarter landed on " << quarter.getSideUp() << ".\n";
- if (quarter.getSideUp() == "heads")
- {
- balance += 0.25;
- wonThisRound += 0.25;
- }
- dime.toss();
- cout << "The dime landed on " << dime.getSideUp() << ".\n";
- if (dime.getSideUp() == "heads")
- {
- balance += 0.10;
- wonThisRound += 0.10;
- }
- nickel.toss();
- cout << "The nickel landed on " << nickel.getSideUp() << ".\n";
- if (nickel.getSideUp() == "heads")
- {
- balance += 0.05;
- wonThisRound += 0.05;
- }
- cout << "\nYou won $" << fixed << setprecision(2) << wonThisRound << " this round! Your current balance is $" << fixed << setprecision(2) << balance << ".\n\n";
- }
- if (balance == 1.00)
- {
- cout << "You win! Your balance is exactly $1.00.\n";
- }
- else
- {
- cout << "You didn't win this time, your balance was $" << balance << ". Try again!\n";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment