Question

C++ Bank Account Program

Asked by: veeaechone

I'm trying to get this program to compile.  I'm sure I'm missing something (probably a lot!)  Please take a look at my files and let me know where I am going wrong.  Please and thank you.

#include "BankAccount.h"
#include "CheckingAccount.h"
#include <iostream>
#include <iomanip>
 
using namespace std;
 
int main ()
{
 BankAccount b;
 CheckingAccount c;
 b.setBankAccount("Jane", "Doe", 123456);
 b.printBankAccount();
 char choice;
 
 
            
do{
   cout << "Please select a banking activity" << endl;
   cout << "1.  Deposit"  << endl;
   cout << "2.  Withdrawal" << endl;
   cout << "3.  Account Balance" << endl;
   cout << "4.  Exit" << endl;
   cout << endl;
   cout << " Please enter a choice number -->>  ";
 
choice=toupper(getchar());
switch(choice)
{
	double dep, withdraw;
case '1':
	cout <<"Enter amount of money to deposit:"<< endl;
	cin>>dep;
	cout <<"New Balance: "<<c.balance + dep<<endl;
case '2':
	c.balance;
	if
		(c.balance <= 0) cout << "Invalid Funds, Please make another selection.";
	else {
		cout <<"How much would you like to withdrawal?"<<endl;
		cin>>withdraw;
		cout<<"New Balance: $"<<c.balance - withdraw<<endl;
	}
case '3':
	c.balance;
case '4':
default:
	cout<<"Invalid menu item...Please re-enter your choice"<<endl;
 
 
while(choice != 4);              
 
return 0;
}
 
#include <iostream>
#include <iomanip>
 
using namespace std;
 
class BankAccount
{
public:
	void setBankAccount(string fName, string lName, int acctNum);
	void printBankAccount() const;
	
private:
	string firstName;
	string lastName;
	int accountNumber;
};
 
 
void BankAccount::setBankAccount(string fName, string lName, int acctNum)
{
	firstName = fName;
	lastName = lName;
	accountNumber = acctNum;
}
 
void BankAccount::printBankAccount() const
{
	cout<<"Hello, "<<firstName<<" "<<lastName<<" Account Number: "<<accountNumber<<endl;
}
 
#include <iostream>
#include <iomanip>
 
using namespace std;
 
class CheckingAccount
{
 
public:
static double balance;	
};
 
double CheckingAccount::balance = 500.00;

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-23 at 15:00:42ID24675152
Tags

C++

Topic

C++ Programming Language

Participating Experts
2
Points
500
Comments
12

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Bank Statement Reconciliations
    My bank provides the ability to download a Bank Satement from its internet site for the purpose of reconciliationand balancing the Bank Statement. When this link is clicked a text file is downloaded and when the download is complete the file associates itself with Excel and t...
  2. bank application
    Hi i required to write the simple online banking system that allow customer to make deposit, withdraw and transfer money. I got stuck at how to design the java beans for transaction and customer, i am not sure should i put the method deposit, withdraw and transfer into the cu...
  3. MYOB Bank Reconciliation
    Scenario: We have our main MYOB data file (.dat) stored on the local c:\ (for the accountants computer) and a backup one stored on a network drive (which we no longer use, and the only reason it's still there is if we need to check information from ages ago). The accountant ...
  4. Inheritance -- Bank Account Class
    I have 2 derived classes and would like to understand how to inherit the base class most effectively. For example, how can I keep the base class AccountBalance private instead of protected? Is there a better way to use simple inheritance to derive from the base class as gi...
  5. Quickbooks Bank Reconciliation
    In Quickbooks, the bank reconciliation opening balance no longer agrees with the balance of the same account in Quickbooks. I am not saying it does not match the bank statement, but that one place in Quickbooks (the check register) does not match another (the reconcilation fu...
  6. Bank Assignment
    Here are my parameters to follow: Every Account at the bank keeps track of a balance. In addition, each Account allows users to deposit and withdraw money. Accounts are subdivided into: SavingsAccount. This type of account has an interest rate associated with it. This rate i...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Ravi_KallaPosted on 2009-08-23 at 21:03:31ID: 25165542

Mention what kind of errors you are getting while compiling. It's not the practice in EE to give a direct/complete solution to the problem posted... But, to guide a person towords the solution. This will be benificial to you while programming in the future.

 

by: Infinity08Posted on 2009-08-23 at 22:57:30ID: 25165844

A few problems I spotted by glancing over the code :

1)

>>         double dep, withdraw;

These variable definitions belong outside of the switch.
As a side note : it's good practice to always initialize your variables as soon as you define them, for example :

        double dep = 0.0, withdraw = 0.0;

That avoids a lot of unexpected problems later on. Make sure to initialize them to acceptable values that don't cause problems themselves.



2) You also seem to be missing break; statements at the end of your switch cases. I suggest to read up on switches a bit :

        http://cplusplus.com/doc/tutorial/control/

(scroll down to the paragraph on switches)



3)

>>         c.balance;

A statement like that doesn't actually do anything ... So it might as well not have been there.



4) You are missing a few end }'s (for your switch and your do loop for example).



5)

>>         string firstName;

You are using the STL string without including the proper header for it :

        #include <string>



6)

>> static double balance;

Making the balance a static member of the CheckingAccount class would mean that all checking accounts have the same balance ... I'm sure that's not what you intended, right ?




Start by fixing these, and then try compiling/running your code again. If you still have problems, then post the exact error messages you get and/or explain the wrong behavior you're noticing.

 

by: veeaechonePosted on 2009-08-24 at 04:09:56ID: 25167170

This is the only error I received before I submitted the question...

1>LINK : fatal error LNK1561: entry point must be defined

I will work on the suggestions made...thanks!

 

by: veeaechonePosted on 2009-08-24 at 04:16:34ID: 25167202

Disregard that last post...I was looking at the wrong program.

The error I received was...

1>c:\documents and settings\veeachone\my documents\visual studio 2008\projects\seminarthree\seminarthree\seminarthree.cpp(55) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\veeachone\my documents\visual studio 2008\projects\seminarthree\seminarthree\seminarthree.cpp(18)' was matched

(that is where the "do" starts)

 

by: Infinity08Posted on 2009-08-24 at 04:43:42ID: 25167340

>> C1075: end of file found before the left brace '{' at 'c:\documents and settings\veeachone\my documents\visual studio 2008\projects\seminarthree\seminarthree\seminarthree.cpp(18)' was matched

That is because of point 4) in my previous post. If you add the matching } braces for each { brace, that error will go away.

 

by: veeaechonePosted on 2009-08-24 at 04:48:56ID: 25167368

I will work on this and see where I get, thanks!

 

by: veeaechonePosted on 2009-08-24 at 07:59:29ID: 25168969

I have made progress and have gotten it to run but I have a few snags that I hope you can offer some advice on.  My choice #1 works ok but my choice #2 does not.  Did I write the line wrong?  Choice #3 works but it repeats the menu immediately after.  I have not figured out how to exit on choice #4 (please don't roll your eyes, I know I should know that!)  Also, if I make a second choice after the first one the menu also repeats twice.   I'm not asking for you to write any code just point me in the right direction.  Please and thank you.

 

by: veeaechonePosted on 2009-08-24 at 08:00:47ID: 25168989

Sorry, I forgot to include my code....

#include "BankAccount.h"
#include <iostream>
#include <iomanip>
 
using namespace std;
 
int main ()
{
 BankAccount b;
 double balance = 500.00;
 b.setBankAccount("Valerie", "Hull", 123456);
 b.printBankAccount();
 char choice;

 
           
do{
   cout << "Please select a banking activity" << endl;
   cout << "1.  Deposit"  << endl;
   cout << "2.  Withdrawal" << endl;
   cout << "3.  Account Balance" << endl;
   cout << "4.  Exit" << endl;
   cout << endl;
   cout << " Please enter a choice number -->>  ";
 
choice=toupper(getchar());
double dep, withdraw;
switch(choice)
{
      
case '1':
      cout <<"Enter amount of money to deposit:"<< endl;
      cin>>dep;
      cout <<"New Balance: "<<balance + dep<<endl;
      break;
case '2':

      if
            (balance <= 0) cout << "Invalid Funds, Please make another selection.";
      else {
            cout <<"How much would you like to withdrawal?"<<endl;
            cin>>withdraw;
            cout<<"New Balance: $"<<balance - withdraw<<endl;
      }
      break;
case '3':
      cout<<"Your balance is "<<balance<<endl;
      break;
case '4':
      break;
default:
      cout<<"Invalid menu item...Please re-enter your choice"<<endl;
      break;
}
}


while(choice != 4);
{
}
 
return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
 
using namespace std;
 
class BankAccount
{
public:
      void setBankAccount(string fName, string lName, int acctNum);
      void printBankAccount() const;
      
private:
      string firstName;
      string lastName;
      int accountNumber;
};


void BankAccount::setBankAccount(string fName, string lName, int acctNum)
{
      firstName = fName;
      lastName = lName;
      accountNumber = acctNum;
}

void BankAccount::printBankAccount() const
{
      cout<<"Hello, "<<firstName<<" "<<lastName<<" Account Number: "<<accountNumber<<endl;
}

 

by: Infinity08Posted on 2009-08-24 at 11:04:20ID: 25170758

>> My choice #1 works ok but my choice #2 does not.

How does it not work ? I can't see anything obviously wrong (except for what I'll talk about a bit further)


>> Choice #3 works but it repeats the menu immediately after.

All you do in choice 3, is show the balance, and then the code goes back to the beginning of the while loop where the menu is displayed. So what you're seeing is the expected behavior.

If you want to let the user push a button before displaying the menu again, then you'll have to add code for that.


>> I have not figured out how to exit on choice #4

Your do-while loop continues when the loop condition is true :

>> while(choice != 4);

Notice that you compare choice to 4, but choice is a character that would contain '4' when the user made choice 4 from the menu. 4 and '4' are not the same ;)


>> Also, if I make a second choice after the first one the menu also repeats twice.

This is because of your input code. If you use 'cin >>' to get input, you have to be aware that it only extracts the requested data from the input stream, but leaves all the rest on the stream. So, if you write code to get an integer value from the input stream, it will get only that integer value from the stream (possibly skipping leading whitespace), but it will leave anything that follows after it on the stream. More specifically, if the user pressed the ENTER key after the input, the newline character will still be on the input stream.

This means that the next time you use getchar to get the user choice, it will get that newline character first. Your switch doesn't have a case for this newline character, so the switch is skipped, and the code goes back to the beginning of the loop where the menu is shown once more.

To avoid this, consider using a more robust way of getting input, namely by reading the input one line at a time using getline :

        http://cplusplus.com/reference/string/getline/

Read a line of input into a temporary line buffer (of type string), and then get whatever data you need out of that line buffer.
Doing this, ensures that the input stream stays clean, and that no garbage is left on it.

 

by: veeaechonePosted on 2009-08-24 at 11:15:01ID: 31619437

You were very helpful!   Thanks again!!

 

by: veeaechonePosted on 2009-08-24 at 11:15:39ID: 25170873

This is very helpful!!  Thanks again!

 

by: Infinity08Posted on 2009-08-24 at 11:17:01ID: 25170884

No problem. Glad to be of assistance :)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...