% Chris Smith, 999999999 % CSC104, Instructor: Songnian Zhou; TA: Miranda Leung % Assignment 1, PART 5 % a2part5b.t uses int value for 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 : int 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 var temp : int 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 contains 9 digits with no leading zeros if (acct_number < 100000000) or (acct_number > 999999999) then validPassword := 0 % put "bad acct number: ", acct_number else % check if the sum of the digits of account number is divisible by 11 digit_sum := 0 temp := acct_number for i : 1 .. 9 digit_sum := digit_sum + (temp mod 10) temp := temp div 10 % or the above two lines can be replaced by the following line % digit_sum = digit_sum + (acct_num (i) - "0") end for if (digit_sum mod 11 not= 0) then validPassword := 0 % put "bad acct number: sum = ", digit_sum else % check if password is in reversed order of account number temp := 100000000 for i : 1 .. 9 if (acct_number mod 10 not= password div temp) then validPassword := 0 % put "acct number and password don't match at position ", i exit end if acct_number := acct_number div 10 password := password mod temp temp := temp div 10 end for 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 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