fork(3) download
  1. program Receipt
  2. !-----------------------------------------------------------------------------------------------------------
  3. ! Christina Urbanczyk Lab 5 Assignment February 24, 2011
  4. ! This program determines the total cost of purchases made at a department store in the Arcata Plaza.
  5. ! Variables used are:
  6. ! ShirtQuantity:Number of shirts for purchase
  7. ! ShirtTotal: Cost of all shirts for purchase
  8. ! Subtotal:Cost of all purchases before sales tax
  9. ! SalesTax:Tax from total purchase
  10. ! TotalCost: Total cost of purchase
  11. ! PantsQuantity: Number of pants for purchase
  12. ! PantsTotal: Cost of all pants for purchase
  13. ! ShoesQuantity: Number of shoes for purchase
  14. ! ShoesTotal: Cost of all shoes for purchase
  15. ! SuitQuantity: Number of suits for purchase
  16. ! SuitTotal: Cost of all suits for purchase
  17. ! IOerror: Input/Output error
  18. ! GetOrder: Subprogram to request items for purchase
  19. !
  20. ! Input: ShirtQuantity, PantsQuantity, ShoesQuantity, SuitsQuantity
  21. ! Output: ShirtTotal,PantsTotal, ShoesTotal, SuitTotal, Subtotal, SalesTax, TotalCost
  22. !-----------------------------------------------------------------------------------------------------------
  23.  
  24. IMPLICIT NONE
  25. integer, parameter:: dp=selected_real_kind (15) !15 Significant Figures
  26. integer:: ShirtQuantity, PantsQuantity,ShoesQuantity, SuitQuantity, ioerror
  27. real(dp):: ShirtTotal, PantsTotal, ShoesTotal, SuitTotal, Subtotal, SalesTax, TotalCost
  28. real(dp),parameter:: ShoesCost=35.85,SuitCost=125.15,TaxRate=.09, ShirtCost=19.95,PantsCost=22.95
  29.  
  30. CALL GetOrder(ShirtCost,'Shirts',ShirtQuantity)
  31. CALL GetOrder(PantsCost,'Pants',PantsQuantity)
  32. CALL GetOrder(ShoesCost,'Shoes',ShoesQuantity)
  33. CALL GetOrder(SuitCost,'Suits',SuitQuantity)
  34.  
  35. !Calculate subtotal of individual items
  36. ShirtTotal= ShirtQuantity*ShirtCost
  37. PantsTotal= PantsQuantity*PantsCost
  38. ShoesTotal= ShoesQuantity*ShoesCost
  39. SuitTotal= SuitQuantity*SuitCost
  40.  
  41. !Calculate subtotal of all items
  42. Subtotal= ShirtTotal+PantsTotal+ShoesTotal+SuitTotal
  43.  
  44. !Calculate sales tax of purchase
  45. SalesTax= Subtotal*TaxRate
  46.  
  47. !Calculate total cost of purchase
  48. TotalCost= Subtotal+SalesTax
  49.  
  50. !Print receipt for purchase
  51. IF (Subtotal/=0) THEN
  52. write (*,*) "|--------------------------------------------|"
  53. write (*,*) "| Christina's Store |"
  54. write (*,*) "| The Plaza |"
  55. write (*,*) "| Arcata, CA 95521 |"
  56. write (*,*) "| |"
  57. write (*,*) "|--------------------------------------------|"
  58. write (*,*) "| ITEM NUMBER COST |"
  59. write (*,*) "|--------------------------------------------|"
  60. END IF
  61.  
  62. IF (Subtotal<=0) THEN
  63. write (*,*) "Thanks for coming to Christina's Store. Have a good day."
  64. END IF
  65.  
  66. IF (ShirtTotal>0) THEN
  67. write (*,'(T2,A7,T22,I2,T39,F6.2,T47,A1)') "| Shirt" ,ShirtQuantity,ShirtTotal,"|"
  68. write (*,*) "|--------------------------------------------|"
  69. END IF
  70.  
  71. IF (PantsTotal>0) THEN
  72. write (*,'(T2,A7,T22,I2,T39,F6.2,T47,A1)') "| Pants" ,PantsQuantity,PantsTotal,"|"
  73. write (*,*) "|--------------------------------------------|"
  74. END IF
  75.  
  76. IF (ShoesTotal>0) THEN
  77. write (*,'(T2,A7,T22,I2,T39,F6.2,T47,A1)') "| Shoes" ,ShoesQuantity,ShoesTotal,"|"
  78. write (*,*) "|--------------------------------------------|"
  79. END IF
  80.  
  81. IF (SuitTotal>0) THEN
  82. write (*,'(T2,A6,T22,I2,T39,F6.2,T47,A1)') "| Suit" ,SuitQuantity,SuitTotal,"|"
  83. write (*,*) "|--------------------------------------------|"
  84. END IF
  85.  
  86. IF (Subtotal>0) THEN
  87. write (*,'(T2,A26,T39,F6.2,T47,A1)') "| Subtotal",Subtotal,"|"
  88. write (*,*) "|--------------------------------------------|"
  89. write (*,'(T2,A19,T39,F6.2,T47,A1)') "| Sales Tax",SalesTax,"|"
  90. write (*,*) "|--------------------------------------------|"
  91. write (*,*) "|--------------------------------------------|"
  92. write (*,'(T2,A15,T39,F6.2,T47,A1)') "| Total",TotalCost,"|"
  93. END IF
  94.  
  95. IF (Subtotal>0) THEN
  96. write (*,*) "|--------------------------------------------|"
  97. write (*,*) "| THANK YOU |"
  98. write (*,*) "|--------------------------------------------|"
  99. END IF
  100.  
  101. CONTAINS
  102. !--GetOrder--------------------------------------------------------------------------------------------
  103. ! The subprogram asks the shopper for the amount of items for purchase to calculate cost of each item.
  104. ! ACCEPTS: ItemCost,ItemName
  105. ! RETURNS: NumItem
  106. !------------------------------------------------------------------------------------------------------
  107. SUBROUTINE GetOrder(ItemCost,ItemName,NumItem)
  108.  
  109. real(dp),INTENT(in)::ItemCost
  110. character(*),INTENT(in)::ItemName
  111. integer,INTENT(out)::NumItem
  112.  
  113. DO
  114. write (*,'("How many ",A," would you like to buy at ",F6.2,"?")') ItemName,ItemCost
  115. read (*,*,iostat=ioerror) NumItem
  116. IF (ioerror/=0) THEN
  117. write (*,*) "Please enter a positive integer."
  118. ELSE IF (NumItem<0) THEN
  119. write (*,*) "Quantity cannot be a negative value. Please reenter item quantity you would like to purchase."
  120. ELSE IF (NumItem>1000) THEN
  121. write (*,*) "Item quantity requested is not available. Please enter a smaller number of items to purchase."
  122. ELSE
  123. IF (NumItem>=0 .and. NumItem<=1000) EXIT
  124. END IF
  125. END DO
  126.  
  127. END SUBROUTINE
  128.  
  129. END PROGRAM
  130.  
Success #stdin #stdout 0s 2624KB
stdin
cat
0
5
5
3
stdout
How many Shirts would you like to buy at  19.95?
 Please enter a positive integer.
How many Shirts would you like to buy at  19.95?
How many Pants would you like to buy at  22.95?
How many Shoes would you like to buy at  35.85?
How many Suits would you like to buy at 125.15?
 |--------------------------------------------|
 |            Christina's Store               |
 |                The Plaza                   |
 |             Arcata, CA 95521               |
 |                                            |
 |--------------------------------------------|
 | ITEM             NUMBER              COST  |
 |--------------------------------------------|
 | Pants              5               114.75  |
 |--------------------------------------------|
 | Shoes              5               179.25  |
 |--------------------------------------------|
 | Suit               3               375.45  |
 |--------------------------------------------|
 |                 Subtotal           669.45  |
 |--------------------------------------------|
 |         Sales Tax                   60.25  |
 |--------------------------------------------|
 |--------------------------------------------|
 |         Total                      729.70  |
 |--------------------------------------------|
 |                  THANK YOU                 |
 |--------------------------------------------|