Hello guys, I am new to this forum and I'm going to put my code here.
#include <iostream>
#include <string.h>
using namespace std;
const int MAX_ACCOUNT = 12;
const int zero = 0;
bool validAcctNumber(int acctNum, int size);
bool checkAccountUsed(int acctNum, double check[]);
bool saveAccountUsed(int acctNum, double save[]);
void newCheckAcct(int acctNum, double check[]);
void newSaveAcct(int acctNum, double save[]);
void depositCheck(int acctNum, double check[], double amount);
void depositSave(int acctNum, double check[], double amount);
bool withdrawCheck(int accNum, double check[], double amount);
bool withdrawSave(int acctNum, double check[], double amount);
bool getAcctNo(int& value);
void main(){
int choice;
double chk[MAX_ACCOUNT] = {0};
double save[MAX_ACCOUNT] = {0}, amt = 0;
int val;
do{
cout <<"Please choose one of the options" << endl;
cout << endl;
cout << "1)Create your checking account\n";
cout << "2)Create your savings account\n";
cout << "3)Make a deposit for your checking account\n";
cout << "4)Make a deposit for your savings account\n";
cout << "5)Make a withdraw for your checking account\n";
cout << "6)make a withdraw for your savings account\n";
cout << "7)Quit" << endl;
cin >> choice;//enters the choice
switch(choice){ //choice the menu options
//calls the getAcct function
case 1:
cout << "Please enter your checking account number" << endl;
cout << "Your new account: "<< getAcctNo(val) << endl;
chk[val] = 0.0;
break;
case 2:
//calls the getAcct function
cout << "Please enter your savings account number" << endl;
cout << "Your new account: " << getAcctNo(val) << endl;
save[val] = 0.0;
break;
case 3://deposits in checking account
cout << "Please enter your checking account" << endl;
if(getAcctNo(val)){
checkAccountUsed(MAX_ACCOUNT, chk);
depositCheck(MAX_ACCOUNT, chk, amt);
}
break;
case 4:
cout << "Please enter your savings account" << endl;
depositSave(MAX_ACCOUNT, save, amt);
break;
case 5://withdraws in checking account
cout << "Please enter your checking account"<< endl;
getAcctNo(val);
withdrawCheck(MAX_ACCOUNT, chk, amt);
break;
case 6://withdraws in savings account
cout << "Please enter your savings account" << endl;
getAcctNo(val);
withdrawSave(MAX_ACCOUNT, chk, amt);
cout << "Please enter how many would you like to withdraw: "
<< endl;
cin << amt;
break;
default:
cout << "Try Again" << endl;
break;
}
}while((choice != 7));//Users quits
}
bool validAcctNumber(int acctNum, int size)
{
if (acctNum < size && acctNum > 0)
return true;
else
return false;
}
bool checkAccountUsed(int acctNum, double check[])
{
if ((acctNum < MAX_ACCOUNT) && (acctNum > 0 )){
check[acctNum] = 0;
return true;
}
else
return false;
}
bool saveAccountUsed(int acctNum, double save[])
{
if((acctNum < MAX_ACCOUNT) && (acctNum > 0)){
save[acctNum] = 0;
return true;
}
else{
return false;
}
}
void newCheckAcct(int acctNum, double check[]){
int size = 0;
if ((checkAccountUsed(acctNum, check))){
if ( validAcctNumber(acctNum, size)){
cout << "Valid Check Accout" << endl;
}
else{
cout << "Invalid" << endl;
}
}
}
void newSaveAcct(int acctNum, double save[]){
if (saveAccountUsed(acctNum, save))
cout << "Valid Save Account" << endl;
else
cout << "Invalid" << endl;
}
void depositCheck(int acctNum, double check[], double amount){
if (checkAccountUsed(acctNum, check)){
cout << "Please enter how much would you like to deposit\n"
<< "on your checking account" << endl;
cin >> amount;
cout << "Your balance of checking account: $" << amount << endl;
}
}
void depositSave(int acctNum, double save[], double amount){
if (saveAccountUsed(acctNum, save)){
cout << "Please enter how much would you like to deposit\n"
<< "on your savings account" << endl;
cin >> amount;
cout << "Your balance of savings account: $" << amount << endl;
}
}
bool withdrawCheck(int acctNum, double check[], double amount){
if (checkAccountUsed(acctNum, check)){
//cout << "Please enter how much would you like to withdraw\n"
// << "from your checking account" << endl;
// cin >> amount;
if (check[acctNum] - amount > 0){
check[acctNum] = check[acctNum] - amount;
return true;
}
else
return false;
}
return false;
}
bool withdrawSave(int acctNum, double save[], double amount){
if(saveAccountUsed(acctNum,save)){
//cout << "please enter how much would you like to withdraw\n"
// << "from your savings account" << endl;
//cin >> amount;
if (save[acctNum] - amount > 0){
save[acctNum] = save[acctNum] - amount;
return true;
}
else
return false;
}
return false;
}
bool getAcctNo(int& value){
/*int i = 0;
char val[8];
bool inputOK = true;
cin.getline(val, 8);
while( i < (int)strlen(val)){
if (isdigit(val[i])){
}
i++;
}
return false;*/
cin >> value;
return true;
}
On the switch statement, I'm going to press 1 to enter the new checking accout, then it'll say You created a checking account. Then I want to deposit a balance on my check account. But when I enter 3 to deposit, it'll go right back to the menu, and its really driving me crazy. I just want a user something like this
"Please enter your checking account"
user enters and check to see if account is valid before enter the balance otherwise its invalid and goes back to the menu. It should output the balance and goes back to the menu. Any help will be appreciated it, Thanks. I'm having a difficult time with this part. Is there any functions I need to add on switch case?