So this is a project that requires us to use 6 user-defined functions and pointers. It is to basically work like an ATM. The program will need to withdraw, deposit, and or check the balance of the check, savings, and credit accounts
The code below is a snippet of my entire code, I just posted enough so that what I need help on can be answered.
Code:
#define _CRT_SECURE_NO_DEPRECATE#include<stdio.h>
#include<ctype.h>
/* Displays the list of options available. Prompts for the user’s selection and sets the value of the selection*/
void MainMenu(int *option);
/*Asks the user which type of account they would like to access and sets the value of the selection*/
void AccountMenu(char *acctType);
/*Displays the user’s current account balance for the selected account*/
void GetBalance(double balance);
/*Prompts the user for the amount of the withdrawal, determines if there are sufficient funds and updates the selected account if funds are dispensed*/
void MakeWithdrawal(double *balance, char acctType);
/*Prompts the user for the amount of deposit and updates the selected account*/
void MakeDeposit(double *balance);
/*Asks the user if they want another transaction*/
void Keepgoing(char *goAgain);
int main( )
{
int option;
char acctType;
char goAgain;
double balance;
double check = 850.00;
double savings = 2500.00;
double credit = -1850.00;
do
{
MainMenu(&option);
switch (option)
{
case 1:
printf("=============================================================================");
printf("\n\nYou selected 'Check Account Balance'\n");
AccountMenu(&acctType);
switch (acctType)
{
case 'C':
printf("=============================================================================");
printf("\n\nYou selected 'Checking'\n");
break;
case 'S':
printf("=============================================================================");
printf("\n\nYou selected 'Savings'\n");
break;
case 'R':
printf("=============================================================================");
printf("\n\nYou selected 'Credit'\n");
break;
default:
printf("=============================================================================");
printf("\n\nYou have selected an option not supported.\n");
break;
}
break;
case 2:
printf("=============================================================================");
printf("\n\nYou selected 'Deposit'\n");
AccountMenu(&acctType);
switch (acctType)
{
case 'C':
printf("=============================================================================");
printf("\n\nYou selected 'Checking'\n");
printf("How much would you like to deposit to your Checking account? $ ");
MakeDeposit(&balance);
check = check + balance;
printf("\nDeposited funds: $%.2lf\nNew Balance: $%.2lf\n",balance,check);
break;
case 'S':
printf("=============================================================================");
printf("\n\nYou selected 'Savings'\n");
printf("How much would you like to deposit to your Savings account? $ ");
MakeDeposit(&balance);
savings = savings + balance;
printf("\nDeposited funds: $%.2lf\nNew Balance: $%.2lf\n",balance,savings);
break;
case 'R':
printf("=============================================================================");
printf("\n\nYou selected 'Credit'\n");
printf("How much would you like to deposit to your Credit account? $ ");
MakeDeposit(&balance);
credit = credit + balance;
printf("\nDeposited funds: $%.2lf\nNew Balance: $%.2lf\n",balance,credit);
break;
default:
printf("=============================================================================");
printf("\n\nYou have selected an option not supported.\n");
break;
}
break;
default:
printf("=============================================================================");
printf("\n\nYou have selected an option not supported.\n");
printf("=============================================================================");
break;
}
}while(Keepgoing(&goAgain),goAgain == 'Y');
}
void MainMenu(int *option)
{
printf("Choose action:\n\n");
printf("1. Check Balance\n");
printf("2. Deposit\n");
printf("\nEnter number: ");
scanf("%d",option);
}
void AccountMenu(char *acctType)
{
printf("Choose account:\n");
printf("\nC - Checking");
printf("\nS - Savings");
printf("\nR - Credit\n");
printf("\nEnter letter: ");
scanf(" %c",acctType);
*acctType = toupper(*acctType);
}
void GetBalance(double balance)
{
//Help with this function definition please.
}
/*
void MakeWithdrawal(double *balance, char acctType)
{
}
*/
void MakeDeposit(double *balance)
{
double dpst = 0;
scanf("%lf",&dpst);
*balance = dpst;
}
void Keepgoing(char *goAgain)
{
printf("=============================================================================");
printf("\n\nAnother transcation?\n");
printf("Y or N: ");
scanf(" %c",goAgain);
*goAgain = toupper(*goAgain);
printf("=============================================================================");
printf("\n\n");
}
What I need help with is defining the function so that it will access the value of the correct account. Its different from the previous 2 and has stumped me. It was thinking just making balance = check in the case statement would be all I needed, but i need to use the user defined function (assignment requirement).
I don't know what to put inside the function to get the desired account balance printed.
GetBalance(balance);
Calling the function just to test things didnt work out either seeing as I get an error as the program runs "The variable 'balance' is being used without being initialized.
I though a & in the call would solve that but no.
Suggestions?