Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 960
  • Last Modified:

C++ - Checkbook Problem

This is the second problem I need to figure out that is needed by tomorrow.

After many years of being frustratedby a check book that just won't balance you decide to make a program that does it for you.  The program should display a list of choices: D for deposit, C for check, W for withdrawal, and Q for quit.  If D is selected ask for the amount of the deposit, and add it to the account balance.  If the user enters C, ask for the amount of the check and subtract it from the balance.  If the user enters a W, ask for the amount of the withdrawal and subtract it from the balance.  When the user enters a Q, the program should display the opening balance, total amount deposited, total amount withdrawn, total amount of the checks and the final balance.  If the user enters something other than D, W, C, or Q, the program should display an error message and redisplay the menu.  Allow the user to enter either upper or lower case letters.

Here's the sample pseudocode to help with the program code.

   Initialize variables
     total_balance to 0
     total_checks to 0
     total_withdrawals to 0
     total_deposits to 0

   get starting balance

   do ... while loop
      prompt for type of transaction
      get transaction
           increase balance
           increase total_deposits
           decrease balance
           increase total_checks
           decrease balance
           increase total_withdrawals
   end do while loop as Q was pressed

   Display summary data
       show balance
       show total_deposits
       show total_checks
       show total_withdrawals


Thanks for being there.  This will help pull my ass out of the fire.
  • 2
1 Solution
Hi MrParkes,

Post the code and we will try to help with it. We can help you with assignments but we can't do them for you.

MrParkesAuthor Commented:
Here is yet another beginner try at coding C++.  I know in my code that I am supposed to show an acccumulator of some kind but I'm not sure how.  I also have to show the summary somehow.

#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main ()

      int            transaction_code,

      cout << setprecision(2)
             << setiosflags(ios::fixed)
             << setiosflags(ios::showpoint);

      total_balance = total_checks = total_withdrawals = total_deposits = 0;

;      cout << "Enter the starting balance: ";
      cin >> total_balance;

      cout << endl;
      cout << "Enter the transaction code according to the following."
             << endl << endl;
      cout << "Deposit,            enter D" << endl;
      cout << "Check,                  enter C" << endl;
      cout << "Withdrawal,      enter W" << endl;
      cout << "Quit                  enter Q" << endl << endl;
      cout << "Please make your selection: ";

      transaction_code = cin.get();

      switch (transaction_code)
            case 'D':
            case 'd':
            case 'C':
            case 'c':
            case 'W':
            case 'w':
            case 'Q':
            case 'q':
            cout << endl << endl
                   <<"Invalid Transaction Code!  Try Again." << endl;

      cout << endl << endl;
      cout << "The balance is " << total_balance << endl;

      cout << "Total Deposits are: " << total_deposits << endl;
      cout << endl;

      cout << "Total Checks are: " << total_checks << endl;
      cout << endl;

      cout << "Total Withdrawals are: " << total_withdrawals << endl;
      cout << endl;

      return 0;

Its a good start ... You need to
a) Put the whole menu printing, choice selection and switch case in a loop. This can be a do while loop organized as

do {
   //print menu
   //read choice
   //switch case to act on choice
} while (choice was not Quit)

b) Put actual processing in the switch case .. e.g.
          case 'D':
          case 'd':
>If D is selected ask for the amount of the deposit, and add it to the account balance.
So in this case, you prompt asker for the amount of money to be depoited .. read the input and add it to total_deposits ... just 3 lines of code and you have a working case!!!
I'm pretty sure you're in the same class as me-I'm having isssues with this program also.  I may seek tutoring-my email is <email id edited out by sunnycoder, Page Editor>if you want to do some sort of online study group thing.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now