Advertisement
steamengines

Chapter 8 homework

Oct 23rd, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.73 KB | None | 0 0
  1. //Christian Ballard
  2. //COSC 1330 - 003
  3. //This program will set a menu for a bank.
  4. #include <iostream>
  5. #include <iomanip>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     cout << "Welcome to Drew's Bank!" << endl;
  11.     cout << endl;
  12.     //Variables
  13.     float balance = 0.0;
  14.     char response = ' ';
  15.     const int NSF = 35;
  16.     float checkValue = 0.0;
  17.     float deposit = 0.0;
  18.     float chargeValue = 0.0;
  19.     char loopQuestion = ' ';
  20.     int checkCount = 0;
  21.     int depositCount = 0;
  22.     int chargeCount = 0;
  23.     float totalCheck = 0.0; //Tracks how much is spent after each transaction
  24.     float totalDeposit = 0.0;//does the same thing here
  25.     float totalCharge = 0.0;//and here
  26.  
  27.  
  28.  
  29.     //find out the users balace
  30.     cout << "What is your current balance? $";
  31.     cin >> balance;
  32.     //Clear the screen
  33.     system("CLS");
  34.     //loopies
  35.     do
  36.     {
  37.         //Bank menu
  38.         cout << "What would you like to do?" << endl;
  39.         cout << endl;
  40.         cout << "For a check, please enter the number '1'" << endl << "For a deposit, please enter the number '2'" << endl << "For a charge, please enter the number '3'" << endl << "To exit, please enter the number '4'" << endl;
  41.         cin >> response;
  42.         system("CLS");
  43.  
  44.         //Switch statement
  45.         switch (response)
  46.         {
  47.         case '1': //The check option
  48.             cout << "You have chosen the check option." << endl;
  49.             cout << "Your current balance is $" << balance << endl << endl;
  50.             cout << "What is the value of the check?" << endl << "$";
  51.             cin >> checkValue;
  52.             system("CLS");
  53.  
  54.             // selection
  55.             if (checkValue <= balance)
  56.             {
  57.                 balance = balance - checkValue;
  58.                 cout << "You have withdrawn $" << checkValue << endl << "Your new balance is $" << balance << endl;
  59.                 checkCount++;
  60.                 totalCheck = checkValue + totalCheck;
  61.             }
  62.             else
  63.             {
  64.                 cout << "You have insufficient funds, an NSF charge of $35.00 has been added to your account." << endl;
  65.                 balance = balance - NSF;
  66.                 cout << "Your new balance is $" << balance << endl;
  67.             }
  68.             break;
  69.         case '2': //The deposit option
  70.             cout << "You have chosen to make a deposit." << endl;
  71.             cout << "Your current balance is $" << balance << endl << endl;
  72.             cout << "How much would you like to deposit?" << endl << "$";
  73.             cin >> deposit;
  74.             balance = deposit + balance;
  75.             cout << "Your new current balance is." << endl << "$" << balance << endl;
  76.             depositCount++;
  77.             totalDeposit = deposit + totalDeposit;
  78.             break;
  79.         case '3': //The charge option
  80.             cout << "You have chosen to make a charge on your account." << endl;
  81.             cout << "Your current balance is $" << balance << endl << endl;
  82.             cout << endl << "What is the value of the charge?" << endl << "$";
  83.             cin >> chargeValue;
  84.             if (chargeValue > balance)
  85.             {
  86.                 cout << "Insufficient funds, card denied." << endl;
  87.             }
  88.             else
  89.             {
  90.                 balance = balance - chargeValue;
  91.                 cout << "Your new current balance is" << endl << "$" << balance << endl;
  92.                 chargeCount++;
  93.                 totalCharge = chargeValue + totalCharge;
  94.             }
  95.             break;
  96.         case '4': //The exit option
  97.             cout << "Thank you for exiting the bank." << endl;
  98.             break;
  99.  
  100.         default: //What happens if the wrong value is entered.
  101.             response = 'z';
  102.         }
  103.  
  104.         if (response == 'z')
  105.         {
  106.             cout << "Please enter '1' for a check, '2' for a deposit, or '3' for a charge. " << endl;
  107.         }
  108.         {
  109.             cout << "Would you like to make another transaction? (Y/N) " << endl;
  110.             cin >> loopQuestion;
  111.         }
  112.         system("cls");
  113.     } while (toupper(loopQuestion) == 'Y');
  114.  
  115.     cout << "Thank you for exiting the bank." << endl << endl;
  116.  
  117.     cout << "Balance              $" << setw(5) << balance << endl;
  118.     cout << "Number of checks     $" << setw(3) << checkCount << endl;
  119.     cout << "Number of deposits   $" << setw(3) << depositCount << endl;
  120.     cout << "Number of charges    $" << setw(3) << chargeCount << endl;
  121.  
  122.  
  123.     system("pause");
  124.     return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement