This commit is contained in:
hairrrrr
2020-04-03 22:17:45 +08:00
parent bc357ea3e9
commit 9bf888e41c
2 changed files with 92 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
#include<stdio.h>
int main(void) {
double balance = 0; // 余额
double credit, debit;
// 菜单,形式可以自己设计,尽量美观一点嘛,不过不用纠结这种界面,不要舍本逐末。
printf("**** ACME checkbook-balancing program ****\n");
printf(" Comands: \n");
printf(" 0 = clear \n");
printf(" 1 = credit \n");
printf(" 2 = debit \n");
printf(" 3 = balance \n");
printf(" 4 = exit \n");
// 题目中已经规定了这些功能用 01234 代替,其实是想让我们用 switch
// 如果你想用 if else 也完全 ok
// 死循环让用户可以重复选择
while (1) {
int choice;
printf("Enter command: ");
scanf("%d", &choice);
switch (choice) {
// 清除账户是一种很“危险”的举动,可以让用户确认一次
case 0: printf("Are you sure to clear your balance?\n");
printf("1 = yes, 0 = no\n");
int isClear;
scanf("%d", &isClear);
if (isClear == 1) {
balance = 0;
printf("clear successfully!\n");
}
break;
case 1: printf("Enter amount of credit: ");
scanf("%lf", &credit);
balance += credit;
break;
case 2: printf("Enter amount of debit : ");
scanf("%lf", &debit);
balance -= debit;
break;
case 3: printf("Current balance: %.2f\n", balance);
break;
case 4: printf("Are you sure to quit?\n");
printf("1 = yes, 0 = no\n");
int isQuit;
scanf("%d", &isQuit);
if (isQuit == 1) {
printf("Goodbye~\n");
return 0;
}
else {
break;
}
default: printf("Illeagl option!\n");
break;
}
}
}

View File

@@ -0,0 +1,22 @@
#### 程序:账薄结算
这个程序帮你理解一种简单的交互式程序设计,我们可以通过这种方式设计菜单。
题目:
开发一个程序用来维护账簿的余额。程序将为用户提供选择菜单:清空余额账户,向账户存钱,从账户取钱,显示当前余额,退出程序。选项用 01234表示。程序的会话类似这样
```c
**** ACME checkbook-balancing program ****
Comands: 0 = clear, 1 = credit, 2 = debit, 3 = balance, 4 = exit
Enter command: 1
Enter amount of credit: 1042.56
Enter command: 2
Enter amount of debit : 133.56
Enter command: 3
Current balance: 909
Ener command: 4
Goodbye~
```