fork(1) download
  1. BEGIN {
  2. while (getline < "bank") {
  3. password[$1] = $2
  4. balance[$1] = $3 }
  5. userid = getuserid()
  6. printf "Your balance is %.2f\n", balance[userid]
  7. while ((cmd = getcommand()) != "Q") {
  8. if (cmd == "D") {
  9. balance[userid] += getamount()
  10. } else if (cmd == "W") {
  11. amt = getamount()
  12. if (amt <= balance[userid]) {
  13. balance[userid] -= amt
  14. } else { print "Can't overdraw account" }
  15. } else { print "Unrecognized command" }
  16. printf "Your balance is %.2f\n", balance[userid] }
  17. print "Thank you for your custom."
  18. for (userid in password) {
  19. if (userid !~ /^ *$/)
  20. print userid, password[userid], balance[userid] > "bank" } }
  21.  
  22. function getuserid( userid, passwd) {
  23. userid = ""; passwd = "hello"
  24. while (passwd != password[userid]) {
  25. printf "%s ", "Enter userid:"; getline userid
  26. printf "%s ", "Enter password:"; getline passwd }
  27. return userid }
  28.  
  29. function getcommand( cmd) {
  30. cmd = "X"
  31. while (cmd !~ /[dDwWqQ]/) {
  32. printf "Enter command: D)eposit, W)ithdrawl or Q)uit: "
  33. getline cmd }
  34. return toupper(cmd) }
  35.  
  36. function getamount( amt) {
  37. amt = "X"
  38. while (amt !~ /[1-9][0-9]*\.?[0-9]*/) {
  39. printf "Enter amount: "; getline amt }
  40. return amt }
Time limit exceeded #stdin #stdout 5s 23336KB
stdin
Standard input is empty
stdout
Standard output is empty