Account code C++

C, C++, Visual C++, C++.Net Topics
Post Reply
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Account code C++

Post by Face » Wed Nov 24, 2010 10:03 pm

Bro,I Made a little code to make unlimited transactions in one account(I wish to improve it to more account)
I need a little help on this to make changes.This is the code,

Code: Select all

/*devoloping system in account transactions
g-sparkz*/

#include<iostream>
using namespace std;

int main(){
    
    int B,W,D,T; //B=Balance,W=Withdraw,D=Deposit,T=Transaction
    char x;
    B=10000; //Starting Balance is 10000
    T=1;
    while(1){
    cout<<endl<<"Transaction Number "<<T<<endl<<endl;
    cout<<"Your Balance is Rs."<<B<<endl<<endl;
    cout<<"Withdraw money press W"<<endl<<"Deposit money press D"<<endl<<endl;
    cin>>x;
    
    if(x=='d'){
               cout<<endl<<"Enter the amount you wanna Deposit - Rs.";
               cin>>D;
               B=B+D;
               cout<<"Your New Balnace is Rs."<<B<<endl<<endl;
               }
    else if(x=='w'){
                 cout<<endl<<"Enter the amount you wanna Withdraw - Rs.";
                 cin>>W;
                 if(W>B){
                         cout<<"Your Balance is Not enouf to withdraw"<<W<<endl;
                         }
                 B=B-W;
                 cout<<"Your New Balnace is Rs."<<B<<endl<<endl;
                 }
                 T++;
}
    system("pause");
    return 1;
    
    }
I wanna change this to make a exit code to this program.How can I make it.My suggestion is to ESC button.
Do I have to learn DATA BASE with C++ to develop this code to add some more account numbers to this?!!
I can use some loops to add account numbers to here 5 or more.But It will make my code bigger & bigger.It will cause many errors & hard to handle.So If you can suggest me any good way I will try to learn it :)
Thanks.
G-sparkz
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Account code C++

Post by Neo » Wed Nov 24, 2010 10:43 pm

I wanna change this to make a exit code to this program.How can I make it.
On the easy way, you can define a letter (say 'e') just as you defined 'd', etc... to exit the programme.
Do I have to learn DATA BASE with C++ to develop this code to add some more account numbers to this?!!
You can use arrays (or data structures like link lists, etc...) which can be used as a memory based data store.

Instead of int B, you can define an array as int B[100];. In this way, you can maintain 100 accounts in memory.
B[0] // your account
B[1] // Nipuna's account
B[2] // Rksk's account
B[3] // Neo's account
...
..
..
B[99] // this is the last account you can access if your array is defined as int B[100];.

You really need to follow the tutorial step-by-step to catch all these simple concepts.
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: Account code C++

Post by Face » Wed Nov 24, 2010 11:01 pm

Thanks for your ideas NEO.I will study that tutorial as much as I have time.:)
I am little slow on PROGRAMMING STUDIES.
I will try on it & post my code soon.
Post Reply

Return to “C/C++ Programming”