gpt4 book ai didi

c - ATM机C语言

转载 作者:行者123 更新时间:2023-11-30 15:37:26 25 4
gpt4 key购买 nike

所以我必须为我的 C 编程入门类(class)制作一个 ATM 机程序,我有点沮丧。我的教授刚刚给我们发电子邮件说:“在任何情况下都不应声明任何指针。我们为您提供了需要使用的指针,这些是函数参数。不应在函数或主函数中重新声明它们.

您还需要实际阅读我在作业中写的评论。大多数(或全部)人都需要向提款函数添加一个参数,因为要正确执行此操作,您需要访问帐户类型。”

我尝试不在主函数中声明指针,但会出现错误。我也不确定是否应该使用 if/else 而不是 switch,因为每次它询问我是否想做另一笔交易时,无论我选择哪一个(1、2、3),程序都会关闭。

我的最后一个问题是我不知道在进行交易时如何更新所选帐户中的金额。 (currball)令人困惑......

我非常感谢我能得到的任何帮助。

//  main.c
// Project Assignment 2
//
// Created by Paul Gleichman on 2/22/14.
// Copyright (c) 2014 Paul Gleichman. All rights reserved.
//

#include <stdio.h>

//* Displays the list of user’s options available
//** Displays the user’s selections and sets the value of the choice
void mainMenu(int *choice);

//Prompts the user for the amount of their deposit and updates the selected account
void DepositMoney( double *currBal);

//Asks the user if they want another transaction
void Repeat(char * doAgain);


//Displays the types of account they would like to access and sets the
//value of the chosen account type
void AccountMenu( char *typeAcct);

//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 WithdrawMoney( double *currBal);

//Displays the user’s current account balance for the selected account
void ShowBalance( double currBal);

int main()
{
double preBal = 4325;
double checking = 575;
double savings = 3750;
double currBal;
int choice;
char doAgain;
char typeAcct;

//Welcome Screen
printf("***** Welcome to Legendary Bank ***** \n");

//Ask user what they'd like to do
printf("** What would you like to do today? ** \n");

//List options
mainMenu(&choice);

switch (choice) {
case 1:
AccountMenu(&typeAcct);
DepositMoney(&currBal);
Repeat(&doAgain);
break;
case 2:
AccountMenu(&typeAcct);
WithdrawMoney(&currBal);
Repeat(&doAgain);
break;
case 3:
AccountMenu(&typeAcct);
ShowBalance(currBal);
Repeat(&doAgain);

}

}

//*Displays the list of user’s options available
//**Displays the user’s selections and sets the value of the choice
void mainMenu(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 DepositMoney( double *currBal)
{
printf("How much would you like to deposit?: \n");
scanf(" %lf", currBal);
printf("Thank you, please take your receipt.\n");
}

//Asks the user if they want another transaction
void Repeat(char * doAgain)
{
int choice;
printf("Would you like to make another transaction?\n");
printf("(Y)es / (N)o ? \n");
scanf(" %c", doAgain);
do {
mainMenu(&choice);
} while (doAgain == 'Y' || doAgain == 'y');
}

//Displays the types of account they would like to access and sets the
//value of the chosen account type
void AccountMenu( char *typeAcct)
{
printf("Please select account: \n");
printf("Choose C for Checking\n");
printf("Choose S for Savings\n");
scanf(" %c", typeAcct);
}

//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 WithdrawMoney( double *currBal)
{
printf("How much would you like to withdraw?\n");
scanf(" %lf", currBal);
printf("Thank you, please take your cash and receipt\n");
}

//Displays the user’s current account balance for the selected account
void ShowBalance( double currBal)
{
printf("You have %lf in your account\n", currBal);
}

最佳答案

你需要做这样的事情。编辑了你的主要和重复功能

int main()
{
double preBal = 4325;
double checking = 575;
double savings = 3750;
double currBal;
int choice;
char doAgain =0;
char typeAcct;

//Welcome Screen
while(1){
printf("***** Welcome to Legendary Bank ***** \n");

//Ask user what they'd like to do
printf("** What would you like to do today? ** \n");

//List options
mainMenu(&choice);
do{
switch (choice) {
case 1:
AccountMenu(&typeAcct);
DepositMoney(&currBal);
Repeat(&doAgain);
break;
case 2:
AccountMenu(&typeAcct);
WithdrawMoney(&currBal);
Repeat(&doAgain);
break;
case 3:
AccountMenu(&typeAcct);
ShowBalance(currBal);
Repeat(&doAgain);
default :
printf("invalid Choice");
Repeat(&doAgain);
}
}while(doAgain == 'Y');
printf("//////////////////NEW TRANSACTION//////////////\n")
}
return 0;
}

在你的重复函数中

void Repeat(char * doAgain)
{
int choice;
printf("Would you like to make another transaction?\n");
printf("(Y)es / (N)o ? \n");
scanf(" %c", doAgain);
}

关于c - ATM机C语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22231897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com