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?

On line 52, you are calling your function "checkAccountUsed(MAX_ACCOUNT, chk)" - I think you want to pass "val" instead of "MAX_ACCOUNT". If you look at the "if" statement in your "checkAccountUsed" function, it says if the passed in account is less than MAX_ACCOUNT - which, of course, it isn't, so the function immediately returns false.

Also, your next function, "depositCheck" also calls "checkAccountUsed", so you may want to eliminate the first call to the function, since your deposit function does it. You probably want to pass "val" to the "depositCheck" function as well.

On line 52, you are calling your function "checkAccountUsed(MAX_ACCOUNT, chk)" - I think you want to pass "val" instead of "MAX_ACCOUNT". If you look at the "if" statement in your "checkAccountUsed" function, it says if the passed in account is less than MAX_ACCOUNT - which, of course, it isn't, so the function immediately returns false.

Also, your next function, "depositCheck" also calls "checkAccountUsed", so you may want to eliminate the first call to the function, since your deposit function does it. You probably want to pass "val" to the "depositCheck" function as well.

Thanks, I think it helps a bit, I'll update the post if there is a problem

K, now I having issues if you go to case 3: I need help on get a user to enter the check account and check if it is valid and so he/she can enter the amount of deposit otherwise it'll say invalid and goes back to the menu. I have no idea, it doesn't say in the textbook. Any ideas?

Thanks.

There are a number of things to look at in your code:

1) validAcctNumber - pretty close, though you should just remove passing of "size" and use your MAX_ACCOUNT constant.
2) checkAccountUsed - other than zeroing out the account amount, this is almost a duplicate of the validAcctNumber function. The purpose of this function (based on its name) is to determine if the account that is passed in is in use. You need to have a way to tell if the account in question is in use. You could initialize the array of checking accounts to -1.0. That way, once you set up a new account and put a zero into it, unused accounts will have a --1.0 (assuming, of course, that bank accounts can't have a negative balance ;) )
3) in "depositCheck", you gather the amount from the user, but you don't store it in the array holding the checking balance. And of course, when you report the balance of the account, you're just reporting back what they deposited, not the balance. You should add the deposit amount into the array, then report the new balance.

Those are a few things to look at. Once you get that working, the other functions are very similar.

Sorry, I've turned it in what I have to the teacher, but thanks anyway.

This article has been dead for over six months. Start a new discussion instead.