So I'm writing a program that gives the user a menu of 4 choices. The first one creates an account, the second deposits money into the account, third displays the account and the last one exits the program. In order to see the balance the user must input their account number which must be provided by the program. So I need three arrays of size 5 that will store five names, account numbers and balances, I know how to keep track of which account and balance is whose. I need help with figuring out how to pass all the functions into passChoice and if passChoice should return something.
My issue is really just problem solving I recently started to code so my code-problem-solving-skills haven't developed yet.
Thank you very much in advance.
In my head I was thinking of the following "Pseudo" code:
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
|
/*
*here are all the prototypes and libraries
*/
int main() {
const int SIZE = 5;
int accountNum[SIZE];
double balance[SIZE];
string name[SIZE];
char choice = displayAndGetInfo();
passChoice(choice, name[], accountNum[], balance[], SIZE);
return 0;
}
char displayAndGetInfo() {
display options to user and get choice
a to create a new account
b to deposit
c to see the balance
d to exit program // after choices a, b or c, the menu should pop up again
return choice;
}
*** passChoice (char choice, string name[], int accountNum[], double balance[], int size) {
switch(choice){
case 'a':{
static int i = 0;
name[i] = getName(size);
accountNum[i] = 100;
balance[i] = 0.00;
i++;
accountNum[i] += 1; //this is so that when the user creates a new account the next account is + 1
}
case 'b':{
double deposit = 0.00;
static int i = 0;
int tempAcctNum=0;
cout << "Enter your account number";
cin >> tempAcctNum;
for (int x = 0; x< size; x++){
if (accountNum[x] == tempAcctNum){
cout << "How much would you like to deposit? ";
cin >> deposit;
cout << endl;
balance[x] += deposit;
cout << name << " your balance is: " << balance[x];
}
i++;
break;
}
case 'c':{
static int i = 0;
int tempAcctNum =0 ;
cout << "Enter your account number";
cin >> tempAcctNum;
for (int x = 0; x< size; x++){
if (accountNum[x] == tempAcctNum){
cout << name[x] << "Your balance is: " << balance[x] << endl;
}
}
i++;
break;
}
case 'd':{
"thank you blah blah blah bye"
return 0; // if I use this then the function return type should be int, or is their a better way?
}
}//switch statment
}// passChoice func
string getName(int size){
static int i=0;
string name[size];
cout << "Enter your name: ";
cin >> name[i];
return name[i];
i++;
}
|
This is the original post:
Banking Application
You have been hired to build a new banking application for a small bank called Bank.
This bank is starting off with just allowing a single back account per customer. They want to be able to offer their Account Sales team a way to create a new account, check the balance for an account, and deposit money into an account using a console driven menu.
Every account will have an account number that you will generate (use a static variable to keep track of the next available account number). Each account will have the name of the customer, and a balance for the account. When an account is first created the balance should be zero dollars.
Below is an example of how the program can look:
******************* Bank Menu************************
1) Create New Account
2) Deposit
3) Show balance
> 1
************************Create Account**************************
Enter Name: Bobby Sue
-------------------------------------------------------------------------------
Account Number: 100
Name: Bobby Sue
Balance: $0
--------------------------------------------------------------------------------
******************* Bank Menu************************
1) Create New Account
2) Deposit
3) Show balance
> 2
****************Deposit***********************
Enter Account Number: 100
Amount to Deposit: $ 500
--------------------------------------------------------
Account Number: 100
Name: Bobby Sue
Balance: $500
--------------------------------------------------------
******************* Bank Menu************************
1) Create New Account
2) Deposit
3) Show balance
>3
******************Balance************************
--------------------------------------------------------
Account Number: 100
Name: Bobby Sue
Balance: $500
--------------------------------------------------------
[END OF SAMPLE OUTPUT]