首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ATM机C语言

ATM机C语言
EN

Stack Overflow用户
提问于 2014-03-06 17:37:42
回答 1查看 7.3K关注 0票数 0

所以我必须为我的Intro编程类做一个自动取款机程序,我有点沮丧。我的教授刚刚给我们发邮件说:“在任何情况下你都不应该声明任何指针,你需要使用的指针是函数参数,它们不应该在函数或主函数中重新声明。

你们也需要读一读我在作业中写的评论。大多数(或全部)用户将需要为取款函数添加一个参数,因为要正确地执行此操作,您将需要访问帐户类型。“

我试图不声明主函数中的指针,但会出现错误。我也不确定是否应该使用if/else而不是switch,因为每当它问我是否想要进行另一个事务时,程序就会关闭,而不管我选择哪一个(1、2、3)。

最后一个问题是,在进行交易时,我不知道如何更新所选帐户中的金额。(醋栗球)很混乱..。

我真的很感激我能得到的任何帮助。

代码语言:javascript
复制
//  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);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-06 18:06:32

你得做这样的事。编辑您的主和重复功能

代码语言:javascript
复制
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;
}

在你的重复功能中

代码语言:javascript
复制
void Repeat(char * doAgain)
{
int choice;
printf("Would you like to make another transaction?\n");
printf("(Y)es / (N)o ? \n");
scanf(" %c", doAgain);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22231897

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档