let rec prompt_for_pin () =
print_string "Please enter your PIN: ";
let input = read_line () in
if input = "1234" then
true
else
(print_string "Invalid PIN. Please try again.\n";
prompt_for_pin ())
let rec prompt_for_transaction account_balance =
print_string "Please select a transaction type (D for deposit, W for withdrawal): ";
let transaction_type = read_line () in
if transaction_type = "D" then
(print_string "Please enter the amount you would like to deposit: ";
let amount = read_float () in
account_balance +. amount)
else if transaction_type = "W" then
(print_string "Please enter the amount you would like to withdraw: ";
let amount = read_float () in
let new_balance = account_balance -. amount in
if new_balance < 0. then
(print_string "Insufficient funds.\n";
account_balance)
else
new_balance)
else
(print_string "Invalid transaction type. Please try again.\n";
prompt_for_transaction account_balance)
let main () =
let account_balance = 1000. in
print_string "Welcome to the ATM.\n";
if prompt_for_pin () then
let new_balance = prompt_for_transaction account_balance in
print_string "Transaction complete. Thank you for using our ATM.\n";
print_string "Your new balance is: ";
print_float new_balance;
print_string "\n"
else
print_string "Sorry, you have entered an invalid PIN.\n"
let () = main ()