我有一个任务,我应该模拟一台ATM机。我遇到的问题是我的代码只显示变量“currBal”中嵌入的最后一个变量而不是全部3.我有一个想法,我可能需要使用指针来区分哪个帐户可以从中拉出来但是我从此失去了。
IE:double currBal =(检查,储蓄,信用);
在运行代码时,预先存在的余额仅显示-750的信用额度,用于检查储蓄和信用(仅应显示信用额度,而检查和储蓄应在存款和取款前显示各自的#defined数量。)仅我现在缺少的是显示所有3个预先存在的余额,并确保提取和存款适用于各自的账户。
感谢您的帮助!
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#define CREDITLIMIT -2000
#define credit -750.00
#define savings 3750.00
#define checking 897.23
//* Displays the list of user’s options available
//** Displays the user’s selections and sets the value of the choice
void entryMenu(int *choice);
//Prompts the user for the amount of their deposit and updates the selected account
void MakeDeposit(double *currBal);
//Asks the user if they want another transaction
void DoMore(char * doAgain);
//Displays the types of account they would like to access and sets the
//value of the chosen account type
void ChoiceMenu(char *acctType);
//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 MoneyToSpend(double *currBal);
//Displays the user’s current account balance for the selected account
void DisplayBalance(double currBal);
int main()
{
double currBal = (checking, credit, savings);
int choice;
char doAgain = 0;
char acctType;
while (1) {
printf("Welcome to MYBANK\n");
printf("Please choose from the following menu\n");
do {
entryMenu(&choice);
switch (choice) {
case 1://Deposit
ChoiceMenu(&acctType);
MakeDeposit(&currBal);
DoMore(&doAgain);
break;
case 2://withdrawal
ChoiceMenu(&acctType);
MoneyToSpend(&currBal);
DoMore(&doAgain);
break;
case 3://account balance
ChoiceMenu(&acctType);
DisplayBalance(currBal);
DoMore(&doAgain);
break;
//choices that are not 1,2,3
default:
printf("invalid Choice");
DoMore(&doAgain);
}
} while (doAgain == 'Y' || doAgain == 'y');
return 1;
}
return 0;
}
//*Displays the list of user’s options available
//**Displays the user’s selections and sets the value of the choice
void entryMenu(int *choice)
{
printf("1 - DEPOSIT \n");
printf("2 - WITHDRAWAL \n");
printf("3 - CHECK ACCOUNT BALANCE \n");
printf("Important: ");
printf("To transfer money first select \n(2) for WITHDRAWAL, then \n(1) for DEPOSIT\n");
scanf(" %d", choice);
}
//Prompts the user for the amount of their deposit and updates the selected account
void MakeDeposit(double *currBal)
{
float deposit;
printf("Please enter the amount of the deposit: ");
scanf("%f", &deposit);
*currBal += deposit;
printf("Thank you, please take your cash and receipt\n");
}
//Asks the user if they want another transaction
void DoMore(char * doAgain)
{
int choice;
printf("Would you like to make another transaction?\n");
printf("(Y)es / (N)o ? \n");
scanf(" %c", doAgain);
}
//Displays the types of account they would like to access and sets the
//value of the chosen account type
void ChoiceMenu(char *acctType)
{
printf("Please select account: \n");
printf("Choose C for Checking\n");
printf("Choose S for Savings\n");
printf("Choose R for Credit\n");
scanf(" %c", acctType);
}
//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 MoneyToSpend(double *currBal, char acctType)
{
float withdrawal;
{
printf("Please enter the amount of the withdrawal: ");
scanf("%f", &withdrawal);
{
if (*currBal < withdrawal)
{
printf("You do not have enough\n\n");
}
else if (*currBal > withdrawal)
{
*currBal -= withdrawal;
}
}
}
}
//Displays the user’s current account balance for the selected account
void DisplayBalance(double currBal)
{
printf("\nYou have %.1f in your account\n", currBal);
}