ATM Machine
Context
Is it an ATM Machine? Is it an AT Machine? Is it an ATM? Who's for certain
Snippet
#include <stdio.h>
int main() {
int pin,
selection;
double balance = 2025.02;
printf("Enter PIN: ");
scanf("%d", &pin);
if (pin == 2160) { // Login success
printf("\nSuccessful login! Select option");
printf("\n(1 - check balance, 2 - withdraw money, 3 - deposit money): ");
scanf("%d", &selection);
switch (selection) {
double amount;
case 1:
// Check Balance case
printf("\nCurrent balance = $%.2lf", balance);
break;
case 2:
// Withdraw Amount case
printf("\nEnter amount to withdraw: ");
scanf("%lf", &amount);
if (amount < 0) { // Amount validity check
printf("\nInvalid withdrawal amount $%.2lf", amount);
} else if (amount > balance) { // Amount validity check
printf("\nCannot withdraw $%.2lf--balance too low", amount);
} else { // Withdrawal execution
balance -= amount;
printf("\nWithdrawing $%.2lf, new balance = $%.2lf", amount, balance);
}
break;
case 3:
// Deposit Amount case
printf("\nEnter amount to deposit: ");
scanf("%lf", &amount);
if (amount <= 0) { // Amount validity check
printf("\nInvalid deposit amount $%.2lf", &amount);
} else { // Depsoit execution
balance += amount;
printf("\nDepositing $%.2lf, new balance = $%.2lf", amount, balance);
}
break;
default:
// Selection validity
printf("\nInvalid option %d", selection);
}
} else { // Fails login
printf("\nInvalid PIN--cannot login!");
}
printf("\n");
}