C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 16th, 2005, 01:35 PM
shane200_ shane200_ is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 2 shane200_ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 28 sec
Reputation Power: 0
Post Banking system C++

I am doing a banking system in C++ for school and I need some help. There are 3 accounts, when you deposit money in the account is should show you the total amount in the account each time you add money to the account and when you withdraw money it should take away the amount withdraw from the balance that is in the account. Can anyone take a look at my codes and see what I am not doing?
Code:
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>


//the list of function prototypes

void Deposit();
void Withdraw();
void Query();
void Show();
void Exit();
char Menu();

int acc, dep, with;
int add = dep + with; //this should add both the deposit and withdraw to give total
int sub= dep - with;
//++++++++++++++++++++++++++++++++++++++++++++++++++   +++++++++
int main()
{
char choice;

do{
choice = Menu();
switch(choice)
{
case 'D' : Deposit(); break;
case 'W' :Withdraw();break;
case 'Q' :Query ();break;
case 'S' :Show(); break;
case 'E' :Exit ();break;
default:cout<<"\n\tINVALID ACCOUNT NUMBER ENTERED, PLEASE TRY AGAIN!!!..\n\n\n";

}

}while(choice !='E'); // end of while loop



return 0;
} //This is the end of the main program

//++++++++++++++++++++++++++++++++++++++++++++++++++   ++++++++++++

char Menu()
{
char choice;


cout<<"\tWelcome to Superbank International \n";
cout<<"====================================";
cout<<"\n D Deposit \n ";
cout<<"\n W Withdraw \n";
cout<<"\n Q Query \n";
cout<<"\n S Show all \n";
cout<<"\n E Exit \n";

cout<<"\n\n Option: ";
cin>>choice;


return choice;
}
//+++++++++++++++++++++++++++++++++++++++++++++
void Deposit()
{
system ("cls"); //this will clear the screen


cout<<"Enter the Account Number: ";
cin>>acc;

if ((acc == 25784) ||(acc == 36256)||(acc == 43815) )
{
cout<<"Enter amount to Deposit:$ ";
cin>>dep;
}
else
{
cout<<"\n\n\tSORRY ACCOUNT NUMBER NOT FOUND!!!\n\n";
}
cout<<"\tTRANSACTION APPROVED\n\n";
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^";
cout<<"\n\nThe Balance on Account " <<acc<< "is $" <<add<<endl;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++
void Withdraw()
{
system ("cls");

cout<<"Enter the Account Number: ";
cin>>acc;

if ((acc == 25784) ||(acc == 36256)||(acc == 43815) )
{
cout<<"Enter amount to Withdraw:$ ";
cin>>with;
}
else
{
cout<<"\n\n\tSORRY ACCOUNT NUMBER NOT FOUND!!!\n\n";
}

cout<<"\tTRANSACTION APPROVED\n\n";
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^";
cout<<"\n\nThe Balance on Account " <<acc<< "is $" <<sub<<endl;
}
//++++++++++++++++++++++++++++++++++++++++++++++++
void Query()
{
system("cls");
cout<<"some text later";
}
//++++++++++++++++++++++++++++++++++++++++++++++++++   
void Show()
{
system("cls");
cout<<"It has been printed";
}
//+++++++++++++++++++++++++++++++++++++
void Exit()
{
system("cls");
cout<<"\n\n\t\tTHANK YOU, FOR USING Superbank International ......\n\n";
exit(1); // quit the programme
}

Last edited by B-Con : April 16th, 2005 at 10:06 PM. Reason: [code] tags added

Reply With Quote
  #2  
Old April 16th, 2005, 07:51 PM
astralvoid astralvoid is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 9 astralvoid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 2 m 42 sec
Reputation Power: 0
I think your whole problem lies in how you think this segment of code works:

Code:
    int acc, dep, with;
    int add = dep + with; //this should add both the deposit and withdraw to give total
    int sub= dep - with;
   


Since you are declaring these globally, I'm sure you are thinking that they should be accessable from any function and you are correct. The mistake you are making is in assuming the sub = dep - with actually performs the calculation for you. It only performs the calculation once (when it is declared).

In order to make it work the way you want, you'll need to add code in your depost and withdrawal functions that perform these calculations.

eg.
Code:
   //global declaration
   //added to hold total account value
   int accntbal;
   
   
   //in your Deposit() function after your cin >> dep
   
   accntbal += dep;
   
   
   
   //in your Withdrawal function after your  cin>> with
   
   accnt -= with;
   
   


This should put you on the right track!

Just remember that when you are declaring variables like the global ones at the top, you are simply reserving a name for a piece of memory to hold that value. You have to specifically perform you own operations on any variable.

Hope this helps!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Banking system C++


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT