ATM机C语言

时间:2014-03-06 17:37:42

标签: c

所以我必须为我的Intro to C编程课做一个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);
}

1 个答案:

答案 0 :(得分:1)

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

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);
}