Solution Q5
Solution Q5
DECLARE total_cost ← 0
DECLARE num_items ← 1000
FOR i ← 1 TO num_items
PRINT "Enter item type (1, 2, or 3): "
INPUT item_type PRINT "Enter parts cost: "
INPUT parts_cost
IF item_type = 1 THEN
item_cost ← parts_cost * 1.5
ELSE IF item_type = 2 THEN
item_cost ← parts_cost * 2.5
ELSE IF item_type = 3 THEN
item_cost ← parts_cost * 5.0
ELSE
PRINT "Invalid item type. Please enter 1, 2, or 3."
i←i-1
END IF
PRINT "Item cost: ", item_cost
total_cost ← total_cost + item_cost
NEXT i
average_cost ← total_cost / num_items
PRINT "Average item cost per day: ", average_cost
OR
DECLARE total_cost ← 0
DECLARE num_items ← 1000
FOR i ← 1 TO num_items
PRINT "Enter item type (1, 2, or 3): "
INPUT item_type
PRINT "Enter parts cost: "
INPUT parts_cost
CASE OF item_type
1: item_cost ← parts_cost * 1.5
2: item_cost ← parts_cost * 2.5
3: item_cost ← parts_cost * 5.0
OTHERWISE:
PRINT "Invalid item type. Please enter 1, 2, or 3."
i ← i - 1 // Repeat the iteration for a valid input
END CASE
PRINT "Item cost: ", item_cost
total_cost ← total_cost + item_cost
NEXT i
average_cost ← total_cost / num_items
PRINT "Average item cost per day: ", average_cost