% Chris Smith, 999999999 % CSC104, Instructor: Songnian Zhou; TA: Miranda Leung % Assignment 1, PART 5 % a2part5a.t uses string to read account number % % Note: It is assumed that only non-negative integer values that are % multiples of 10 will be entered at the prompt for dollars. var acct_number, password : string var dollars : int % dollar amount to be withdrawn var digit_sum : int := 0 % sum of all 9 digits of password var dollar_sum : int := 0 % sum of total amount already withdrawn var validPassword : int := 1 % valid password check flag: 1 - yes, 0 - no put " ***** Welcome to ATM ******" put "" put "Please type in your account number: " .. get acct_number put "Please type in your password: " .. get password % check if account number is valid (ie. no leading zeros and contains 9 digits) if acct_number(1) = "0" or length(acct_number) not= 9 then validPassword := 0 % put "bad acct number: ", acct_number else % check for valid password (ie. password is in reversed order of account #, % and sum of digits is divisible by 11) for i : 1 .. 9 if acct_number(i) not= password(10 - i) then validPassword := 0 % put "acct number and password don't match at: ", i, "th digit" exit end if % convert the (i)th digit into a number and add them up digit_sum := digit_sum + strint(password(i)) end for if (digit_sum mod 11) not= 0 then validPassword := 0 % put "password not divisible by 11: ", password, " ", digit_sum end if end if if (validPassword = 1) then loop put "Please enter the amount of cash you want to withdraw: $" .. get dollars put "" exit when dollars = 0 dollar_sum := dollar_sum + dollars if dollar_sum > 200 then put "Sorry - your request pushes you over your cash limit" exit else put "Please pick up $", dollars, ": " .. % deduct in order of largest bill from the withdrawn dollar amount % 20's and 100's need a loop because you might need 2 of them loop exit when (dollars div 100) < 1 put "$100 " .. dollars := dollars - 100 end loop if (dollars div 50) >= 1 then put "$50 " .. dollars := dollars - 50 end if loop exit when (dollars div 20) < 1 put "$20 " .. dollars := dollars - 20 end loop % since it is assumed only multiples of $10 will entered, the % remaining dollar amount should be either $10 or 0 if (dollars = 10) then put "$10 " else put "" end if end if put "" end loop put "Thank you for your business!" else put "" put "Sorry your is not acceptable." end if