c语言atm机高级代码
时间: 2023-07-28 12:10:45 浏览: 45
以下是一个简单的C语言ATM机高级代码示例,包括了基本的ATM机操作,如取款、存款、查询余额等:
```
#include <stdio.h>
int main() {
int option, balance = 10000, amount;
while (1) {
printf("Welcome to the ATM machine!\n");
printf("Please select an option:\n");
printf("1. Check Balance\n");
printf("2. Deposit\n");
printf("3. Withdraw\n");
printf("4. Exit\n");
scanf("%d", &option);
switch(option) {
case 1:
printf("Your balance is %d\n", balance);
break;
case 2:
printf("Enter the amount to deposit: ");
scanf("%d", &amount);
balance += amount;
printf("Deposit successful. Your new balance is %d\n", balance);
break;
case 3:
printf("Enter the amount to withdraw: ");
scanf("%d", &amount);
if (amount > balance) {
printf("Withdrawal failed. Insufficient balance.\n");
} else {
balance -= amount;
printf("Withdrawal successful. Your new balance is %d\n", balance);
}
break;
case 4:
printf("Thank you for using the ATM machine!\n");
return 0;
default:
printf("Invalid option. Please try again.\n");
}
}
}
```
该代码使用了一个无限循环,直到用户选择“退出”选项才结束循环。在每个选项中,用户可以输入要存取的金额,然后更新余额。如果用户尝试提取超过其余额的金额,程序会提示“提款失败,余额不足”。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)