跟踪日期并允许菜单选择的银行系统

时间:2014-03-14 03:42:11

标签: c

我试图创建一个简单的银行业务程序,允许用户从4个选项的列表中进行选择,然后根据用户选择的内容,它将执行该操作,然后询问用户是否想要另一个选项。我还必须跟踪输入的日期,并确保无法输入更早的日期。我已经设置了用户输入,但是我很难找到让选项工作的方法,以及设置日期检查。我考虑过将这些选项放在while循环中但是不确定是否可行。有人可以提供一些帮助吗?

#include <stdio.h>

#define begin_amount 2000

int main(void) {
    int debit, credit, current_date, debit_sum, credit_sum, option; //initialize variables for withdrawing and depositing
    int new_date = 1;
    int x = 3;
    printf("what option do you want?\n");
    scanf("%d", &option);

    printf("Deposit\n");
    printf("Withdrawl\n");
    printf("Print Statement\n");
    printf("Interest\n");

    //deposits
    printf("Please enter todays date?\n"); //ask the user for today's date
    scanf("%d", &current_date);

    printf("how much do you want to credit to your account?\n"); //ask them to input how much they want to deposit
    scanf("%d", &credit);

    printf("Your new balance is %d\n", begin_amount+credit); //print their new balance

    //Withdrawls
    printf("Please enter todays date?\n"); //askt he user to enter today's date
    scanf("%d", &current_date);

    printf("how much do you want to debit to from account?\n"); //ask them how much they want to withdraw
    scanf("%d", &debit);

    printf("Your new balance is %d\n", begin_amount-debit); //print their new balance

    //counting amount of withdrawls and deposits
    printf("Please enter today's date?\n"); //ask the user to enter today's date
    scanf("%d", &current_date);

    return 0;
}

1 个答案:

答案 0 :(得分:0)

我建议为所有选项创建函数,但是如果你只想要一个简单的程序,那么只需要一个带有开关循环的while循环。 即。

while (true) { scanf("%d",&option); switch(option) { case 1: //deposit break; } };

您可以将每个选项视为自己的案例。