You are given the price list of certain equipment (Table 1).
Write a script or function that takes an input for the number of items from each equipment and calculates the total number of equipment, total cost, and average cost per item.
(Table 1: Price List: )
Equipment Price (£)
Power generator 30
Transformer 10
Stepper motor 15
DC motor 8.5
equipment = ["Power generator", "Transformer", "Stepper motor", "DC motor"];
price = [30, 10, 15, 8.5];
n = 4;
tot_number = 0;
tot_cost = 0;
for i=1:n
number = input("Enter number of " + equipment(i) + ": ");
tot_number = tot_number + number;
tot_cost = tot_cost + number * price(i);
end
avg_cost = tot_cost /tot_number;
fprintf("\n");
fprintf("The total number of equipment: %d\n", tot_number);
fprintf("The total cost: £%.2f\n", tot_cost);
fprintf("The average cost £%.2f per item\n", avg_cost);
Comments
Leave a comment