0% found this document useful (0 votes)
17 views2 pages

Solution Q5

The document outlines a procedure for calculating the total and average cost of items based on their type and parts cost. It prompts the user to input the item type and parts cost for 1000 items, applying different multipliers based on the item type. The program handles invalid inputs by repeating the iteration until a valid item type is entered and then calculates the average item cost at the end.

Uploaded by

zazaaba90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Solution Q5

The document outlines a procedure for calculating the total and average cost of items based on their type and parts cost. It prompts the user to input the item type and parts cost for 1000 items, applying different multipliers based on the item type. The program handles invalid inputs by repeating the iteration until a valid item type is entered and then calculates the average item cost at the end.

Uploaded by

zazaaba90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like