C语言ATM代码
时间: 2023-07-09 07:16:42 浏览: 92
以下是一个简单的C语言ATM机代码示例,包括账户余额、取款和存款功能。
```c
#include <stdio.h>
int main()
{
int balance = 1000, choice, amount;
printf("Welcome to the ATM machine!\n");
printf("Your current balance is %d\n\n", balance);
while(1) {
printf("Please select an option:\n");
printf("1. Withdraw money\n");
printf("2. Deposit money\n");
printf("3. Exit\n\n");
scanf("%d", &choice);
switch(choice) {
case 1:
printf("Enter the amount to withdraw: ");
scanf("%d", &amount);
if(amount > balance) {
printf("Insufficient balance! Please try again.\n\n");
} else {
balance -= amount;
printf("Withdrawal successful. Your new balance is %d\n\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\n", balance);
break;
case 3:
printf("Thank you for using our ATM. Goodbye!\n");
return 0;
default:
printf("Invalid option! Please try again.\n\n");
break;
}
}
}
```
这是一个非常基本的ATM机程序,可以根据需求进行修改和扩展。请注意,这只是一个演示用代码,实际上ATM机的安全性非常重要,需要进行更严格的安全措施和防范措施。
阅读全文