atm取款机c语言代码
时间: 2023-09-22 10:15:32 浏览: 178
以下是一个简单的 ATM 取款机 C 语言代码:
```c
#include <stdio.h>
int main()
{
int balance = 10000, withdraw, deposit;
int option, pin = 1234;
printf("Welcome to the ATM!\n");
printf("Enter your PIN: ");
scanf("%d", &pin);
if (pin != 1234) {
printf("Invalid PIN. Try again.\n");
return 0;
}
printf("Select an option:\n");
printf("1. Check balance\n");
printf("2. Withdraw money\n");
printf("3. Deposit money\n");
scanf("%d", &option);
switch (option) {
case 1:
printf("Your balance is %d\n", balance);
break;
case 2:
printf("Enter the amount to withdraw: ");
scanf("%d", &withdraw);
if (withdraw > balance) {
printf("Insufficient balance.\n");
} else {
balance -= withdraw;
printf("Your new balance is %d\n", balance);
}
break;
case 3:
printf("Enter the amount to deposit: ");
scanf("%d", &deposit);
balance += deposit;
printf("Your new balance is %d\n", balance);
break;
default:
printf("Invalid option selected.\n");
}
printf("Thank you for using the ATM!\n");
return 0;
}
```
这个代码实现了一个简单的 ATM 取款机,包括 PIN 验证、查询余额、取款和存款等功能。当然,这只是一个简单的示例,实际的 ATM 取款机肯定要更复杂和安全。
阅读全文