### banking system

Pages: 12
@ajh32 - I believe that he is a beginner, so map, class, and enum might be over their head...(just saying)
Last edited on
@Ekid - well it should give him some idea of what he needs to do. He can always learn about, stl, classes, pointers, enum's etc...
Hehe, ya i am a beginner, i really dont understand the code, when i run it also, it does not appear anything, it is just blank, please help
Making a class is a good idea but no need to make this thread more complex now.

@ajh32
You made a very advanced code. Please note that david123456 is only just a beginner. That wastes people's time (and you).

@david123456
Do you need a similar code but more simpler and more readable than the awful one? That's an example (or reference), and you should learn some new knowledge (class, struct, pointer, enum) - Find on website CPlusPlus homepage.

Here are some tips for you :
Before doing any exercise :

Determine the algorithm first (draft) : This includes a few steps :
1 - Find the input - output, necessary variables.
Example : Find the average value (a,b)
 Input : a,b (variables) Output : c (Average value)

2 - How many sections? Write down all on a menu.
3 - How to solve that problem? Simply, think or write this on a draft from your mind. There are many methods around.
4 - If you need, map the algorithm. (The exercise will become simpler more)

Now you're having :
- Input - Output
- Necessary variables
- Important sections (Can be separated into function(s))
- A method for a specific algorithm.

Fix syntax errors, check all sections, input, output (You may use a debugger)

(If you need help with anything just ask)

Last edited on
Another huge thank you @ Marie Jackson, its a big help, most especially the tips that you had given me here, the code that you gave me, is running completely, no problem, i discover that there is some problem in turbo c++, so i look for another compiler which is dev c++, i paste your code, perfect, its running completely. Thank you

Another question and help, my professor wants the program to have a function, he describes that each case has its own function , so that it will be cleaner he said, i am now starting to study about the functions, and trying to do it, but the project will be submitted, this saturday, here in my country its thursday, so maybe again you can help me, rebuild the code to put some functions on it, here is the code i will paste it, another thank you in advance, dont worry, i am doing and practicing programming, but the time of the professor is giving me a headache, please, thank you

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 #include #include #include #include #include #define OPEN 1 #define DEPOSIT 2 #define WITHDRAW 3 #define BALANCE 4 #define CLOSEACCOUNT 5 #define EXIT 6 int main() { //////////////////////Init char name[64]; bool openBank = false; double balance = 0; double d = 0; // custom input int choice; bool bQuit = false; //////////////////////Start while(bQuit == false) { system("cls"); cout <<"\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"; cout <<"\t\tBANKING SYSTEM"; if(openBank){ cout << "\tName : \"" << name << "\" Balance : " << balance; }cout <<"\n"; cout <<"\t[1] Open an Account\n"; cout <<"\t[2] Deposit Transaction\n"; cout <<"\t[3] Withdrawal Transaction\n"; cout <<"\t[4] Balance Inquiry\n"; cout <<"\t[5] Close Account\n"; cout <<"\t[6] Exit\n\n"; cout <<"\tPlease choose: "; cin >> choice; cout <<"\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n"; Case : if(choice != OPEN && openBank == false && choice !=CLOSEACCOUNT && choice != EXIT) {cout <<"\tPlease, open the account first\n";choice = OPEN;} //////////////////////Command switch(choice) { ////////////////////////////////////////////////////////////////////////////////////////////////////// case OPEN : if(openBank == false){ cout <<"\tAccount name : ";cin >> name;openBank = true;balance = 0; cout <<"\tWell done " << name << "! The Bank System has been opened !!!\n"; } else {cout <<"\tYou'll need to close the account first !\n";choice = CLOSEACCOUNT;goto Case;} break; ////////////////////////////////////////////////////////////////////////////////////////////////////// case DEPOSIT : d = 0; cout <<"\tEnter the amount to deposit (min 500) : "; cin >> d; while(d < 500) { cout <<"\tYou enter is below the minimum deposit. Please enter again.\n\n"; cin >> d; } balance = balance + d; break; ////////////////////////////////////////////////////////////////////////////////////////////////////// case WITHDRAW : cout <<"\tEnter the amout to withdraw : "; cin >> d; while(d > balance || d<=0 || balance - d < 500){ cout <<"\t Please enter again.\n\n"; cin>>d; } balance = balance - d; break; ////////////////////////////////////////////////////////////////////////////////////////////////////// case BALANCE : cout<<"\tYour current balance is: "<> choice; if(choice == 1){name[0] = 0;openBank = false;} } break; ////////////////////////////////////////////////////////////////////////////////////////////////////// case EXIT : bQuit = true; break; } ////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////End case commands } //////////////////////End Bank loop return 0; } //////////////////////End program...

The professor wants each case inside the switch, or each options in banking system is using functions. Thanks, many thanks
A simple trick (Do you know well about "functions?") :
1- Put out all variables out of the function main() (will be become global variables), like this :
 1234567891011 //////////////////////Init char name[64]; bool openBank = false; double balance = 0; double d = 0; // custom input int choice; bool bQuit = false; //////Before.... int main() {

2- Create your own functions, simply move all code from a proper command section (switch case) then paste it into your function - Exception : "break;"

For example a section :
 12345678910 case OPEN : ///////////////////////////////////////////////////////////////////////////////////// if(openBank == false){ cout <<"\tAccount name : ";cin >> name;openBank = true;balance = 0; cout <<"\tWell done " << name << "! The Bank System has been opened !!!\n"; } else {cout <<"\tYou'll need to close the account first !\n";choice = CLOSEACCOUNT;goto Case;} ///////////////////////////////////////////////////////////////////////////////////// break;

Then the function "OPEN" :
 1234567891011 void OpenAccount() { ///////////////////////////////////////////////////////////////////////////////////// if(openBank == false){ cout <<"\tAccount name : ";cin >> name;openBank = true;balance = 0; cout <<"\tWell done " << name << "! The Bank System has been opened !!!\n"; } else {cout <<"\tYou'll need to close the account first !\n";choice = CLOSEACCOUNT;} ///////////////////////////////////////////////////////////////////////////////////// }

and again OPEN section (just only call the function you've just created) :
 12345 case OPEN : ///////////////////////////////////////////////////////////////////////////////////// OpenAccount();/*Exception*/if(choice == CLOSEACCOUNT)goto Case; ///////////////////////////////////////////////////////////////////////////////////// break;

This is the simplest trick method for a beginner. Hope all goes well :).......
Last edited on
Thanks a lot, this is the best forum ever, thanks God Bless, ill try this for sure.
Hi marie jackson,

Its ok, Thanks, but i am having a problem with the arguments,, maybe you can give ma an example , like functions for case withdraw and deposit, am i going to use arguments, please help thanks
Last edited on
All simple functions above have no parameters and just return 'void' (return nothing)
(But sorry, because in short I'm at work (mobile))
Are you worrying about function parameters? I'll come back soon with a few suggestions maybe... :) But, ask you first : What do you mean by 'arguments'... And your problem... more details please?
Last edited on
Hi , because when i am reading the tutorial, they are stating something about functions and arguments, like return and accept, my question is, in my program in my switch case for deposit and withdraw, can i do also the functions that i did that you teach here, i mean when you did the case for OpenAccount? Thanks, sorry for using your time, God Bless you,
@ajh32 - Good point.
Hi marie jackson, sorry for so much questions, i am just curious about my two switch case which is the deposit and the withdraw, can i also use the function that you showed to me?with these deposit and withdraw? thanks
 1234567891011 void Withdraw() { cout <<"\tEnter the amout to withdraw : "; cin >> d; while(d > balance || d<=0 || balance - d < 500){ cout <<"\t Please enter again.\n\n"; cin>>d; } balance = balance - d; } /////////////////////////////////////////////////////////////////////////////////////////////////

This works, but that (maybe) is the function you want :

 1234567891011 int Withdraw(int bal) { cout <<"\tEnter the amout to withdraw : "; cin >> d; while(d > bal || d<=0 || bal - d < 500){ cout <<"\t Please enter again.\n\n"; cin>>d; } return (bal - d); bal = bal - d; return bal; }

This function I added the parameter "int bal". This means before calling this function you must give the function all necessary parameters (In this case the function Withdraw() requires an "int" parameter (bal)). Now, please look at the simple example :

 1234 int Average(int a, int b) { return (a + b) / 2; }

int c = Average(10, 24);

You can see this function has a "int" returning value. The parameters are "a", "b", and the code is just a final value of the expression "(a + b) / 2"
And the code : "c = Average(10, 24);" I input in order a = 10, b = 24
So, making a function is very easy. Remember before making any function :

1- Name
2- Parameter list (Optional)
3- Returning value (Optional) - Consider about the target carefully
4- Code inside

And the function I mentioned above :
Name : Withdraw
Parameter list : int (bal)
Returning value : bal (the remaining balance)
Code : Input, withdraw....
Target : Get the remaining balance

And the use of this function :
 123 case WITHDRAW : balance = Withdraw(balance); break;

(See cPlusPlus documentation & tutorials for more details)

And, the similar function :

 123456789101112131415 int Deposit(int bal) { d = 0; cout <<"\tEnter the amount to deposit (min 500) : "; cin >> d; while(d < 500) { cout <<"\tYou enter is below the minimum deposit. Please enter again.\n\n"; cin >> d; } bal = bal + d; return bal; }

Do you know the hand-checking skill?
Last edited on
Topic archived. No new replies allowed.
Pages: 12