SilverhandX

coinmain.cpp

Mar 7th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. #include "coin.h"
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     Coin quarter;
  10.     Coin dime;
  11.     Coin nickel;
  12.  
  13.     double balance = 0;
  14.  
  15.     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";
  16.  
  17.     while (balance < 1.00)
  18.     {
  19.         system("pause");
  20.         cout << endl;
  21.  
  22.         double wonThisRound = 0;
  23.         cout << "Start of Round:\n";
  24.        
  25.         quarter.toss();
  26.         cout << "The quarter landed on " << quarter.getSideUp() << ".\n";
  27.         if (quarter.getSideUp() == "heads")
  28.         {
  29.             balance += 0.25;
  30.             wonThisRound += 0.25;
  31.         }
  32.  
  33.         dime.toss();
  34.         cout << "The dime landed on " << dime.getSideUp() << ".\n";
  35.         if (dime.getSideUp() == "heads")
  36.         {
  37.             balance += 0.10;
  38.             wonThisRound += 0.10;
  39.         }
  40.  
  41.         nickel.toss();
  42.         cout << "The nickel landed on " << nickel.getSideUp() << ".\n";
  43.         if (nickel.getSideUp() == "heads")
  44.         {
  45.             balance += 0.05;
  46.             wonThisRound += 0.05;
  47.         }
  48.  
  49.         cout << "\nYou won $" << fixed << setprecision(2) << wonThisRound << " this round! Your current balance is $" << fixed << setprecision(2) << balance << ".\n\n";
  50.     }
  51.  
  52.     if (balance == 1.00)
  53.     {
  54.         cout << "You win! Your balance is exactly $1.00.\n";
  55.     }
  56.  
  57.     else
  58.     {
  59.         cout << "You didn't win this time, your balance was $" << balance << ". Try again!\n";
  60.     }
  61.  
  62.     return 0;
  63. }
Add Comment
Please, Sign In to add comment