PRO CHANGE, payment, purchase, money ; ;This will calculate the change and tender ; to be returned to the customer ; ; calculate change return0=payment-purchase change1=return0 ;calculate Twenties return1=return0 MOD 20. twenty=(return0-return1)/20. ;calculate Tens return2=return1 MOD 10 ten=(return1-return2)/10. ;calculate 5's return3=return2 MOD 5 five=(return2-return3)/5. ;calculate 1s return4=return3 MOD 1 one=(return3-return4)/1. ;calculate quarters return6=return4 MOD .25 quarter=(return4-return6)/0.25 ;calculate dimes return7=return6 MOD .1 dime=(return6-return7)/.1 ;calculate nickels return8=return7 MOD .05 nickel=(return7-return8)/0.05 ;calculate pennies - the +0.001 makes the Integer print work ; a value of 2 pennies would not return the correct amount ; as an integer display, so it has to be slightly larger. penny=(return8)/0.01+.001 money=[change1, twenty, ten, five, one, quarter, dime, nickel, penny] ;PRINT, money[8], money[8]+.001, format='(f6.2, i6)' END ;**************************main program******************************** PRO idl_hw03_acp ; ;This will allow for calculation of change. Just execute the program ; and feed in the input ; PRINT, 'Please enter the purchase amount (<$200) ' READ, purchase PRINT, 'Please enter the payment' READ, payment ; ;This is the logic part for 3 cases ;1. Insufficient funds ;2. Exact Change ;3. Change coming ; (and the bonus feature - it's a gas) ; IF payment LT purchase THEN BEGIN ; Insufficient funds PRINT, 'Insufficient Funds', 'You owe', ABS(payment-purchase), FORMAT='(a,/,a," $",F6.2)' ENDIF ELSE BEGIN ; If there is enough money CHANGE, payment, purchase, money IF money[0] EQ 0 THEN BEGIN ; Exact change PRINT, 'No Change Coming', FORMAT='(a)' ENDIF ELSE BEGIN ; This is if there is change IF money[0] GT 0 THEN PRINT, 'Your change is $', money[0], FORMAT='(a, F6.2)' IF money[1] GT 0 THEN PRINT, money[1], '20s', FORMAT='(I6," ", a)'; twenties IF money[2] GT 0 THEN PRINT, money[2], '10s', FORMAT='(I6," ", a)'; tens IF money[3] GT 0 THEN PRINT, money[3], '5s', FORMAT='(I6," ", a)'; fives IF money[4] GT 0 THEN PRINT, money[4], '1s', FORMAT='(I6," ", a)'; ones IF money[5] GT 0 THEN PRINT, money[5], 'Quarters', FORMAT='(I6," ", a)'; Quarters IF money[6] GT 0 THEN PRINT, money[6], 'Dimes', FORMAT='(I6," ", a)'; Dimes IF money[7] GT 0 THEN PRINT, money[7], 'Nickels', FORMAT='(I6," ", a)'; Nickels IF money[8] GT 0 THEN PRINT, money[8], 'Pennies', FORMAT='(I6," ", a)'; Pennies ENDELSE PRINT, 'Just a bonus, you can buy', money[0]/3.959, $ ' gallons of gas on Saturday with your change.', FORMAT='(a,F7.3,a)' ENDELSE ; ; END