Solved

C++ - Checkbook Problem

Posted on 2006-10-26
6
871 Views
Last Modified: 2008-02-01
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.

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

Process
   get starting balance

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

OUTPUT
   Display summary data
       show balance
       show total_deposits
       show total_checks
       show total_withdrawals

END

Thanks for being there.  This will help pull my ass out of the fire.
0
Comment
Question by:MrParkes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17810909
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.

Cheers!
sunnycoder
0
 

Author Comment

by:MrParkes
ID: 17815587
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,
                  total_balance,
                  total_checks,
                  total_withdrawals,
                  total_deposits,
                  Quit;

      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: ";

      cin.get();
      transaction_code = cin.get();

      switch (transaction_code)
      {
            case 'D':
            case 'd':
                  total_deposits;
                  break;
            case 'C':
            case 'c':
                  total_checks;
                  break;
            case 'W':
            case 'w':
                  total_withdrawals;
                  break;
            case 'Q':
            case 'q':
                  Quit;
                  break;
            default:
            cout << endl << endl
                   <<"Invalid Transaction Code!  Try Again." << endl;
            exit(1);
            break;
      }

      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;

}
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 17816954
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':
               total_deposits;
               break;
>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!!!
0
 

Expert Comment

by:mtrocine
ID: 17868248
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.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Getting IP address 8 124
Template syntax for variable length arrays 9 79
c++ syntax question 9 66
c++  placing data into a form and an editbox 5 49
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question