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)

Next, write your code
Now you're having :
- Input - Output
- The menu
- 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)

And your program is totally ready!!!
(If you need help with anything just ask)

Hope it's helpful.
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

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
99
100
101
102
103
104
105
106
107
108
#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include<iostream.h>
#include<conio.h>

#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: "<<balance<<"\n";
cout <<"Please enter to go back to the main menu. ";getch();
break;
//////////////////////////////////////////////////////////////////////////////////////////////////////
case CLOSEACCOUNT :
if(openBank == false)cout <<"The bank is closed. No need to close now.\n\n"; 
else
{
	cout <<"Please [1] to delete Account and [0] to go back to main menu: "; cin >> 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 :
1
2
3
4
5
6
7
8
9
10
11
//////////////////////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 :
1
2
3
4
5
6
7
8
9
10
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" :
1
2
3
4
5
6
7
8
9
10
11
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) :
1
2
3
4
5
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
1
2
3
4
5
6
7
8
9
10
11
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 :

1
2
3
4
5
6
7
8
9
10
11
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 :

1
2
3
4
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 :
1
2
3
case WITHDRAW :
balance = Withdraw(balance); 
break;


(See cPlusPlus documentation & tutorials for more details)

And, the similar function :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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