0
我想做一個簡單的銀行業務程序,允許用戶從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", ¤t_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", ¤t_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", ¤t_date);
return 0;
}
然後我會爲語句選項添加情況2,然後等等等等? – user3230393
是的。但是,您不必將其稱爲案例1,案例2.將數字更改爲您希望用戶輸入的任何內容。還要確保用戶知道要輸入什麼。 'code'printf(「1 - Deposit \ n」); printf(「2 - Withdrawl \ n」); printf(「3 - 打印聲明\ n」); printf(「4 - Interest \ n」);'code' – Kirby
我明白了。那麼我有他們,但現在如何做到這一點,當有人選擇「存款」,然後程序詢問用戶的日期和他們想存多少?我能否以某種方式將它鏈接到我已經用於存款部分的打印和掃描報表? – user3230393