Create a file "parts_inv.dat" that stores on each line a part number, cost, and quantity in inventory, in the following format:123 5.99 52Use fscanfto read this informationand print the total dollar amount of inventory (the sum of the cost multiplied by the quantity for each part).

Respuesta :

Answer:

%Open the file.

fID = fopen('parts_inv.dat');

%Read from the file.

data = fscanf(fID,'%d\t%f\t%d',[3,inf]);

%Close

fclose(fID);

%Restore the data.

data = data';

%Get the size

[rs, cs] = size(data);

%Set value.

invCost = 0;

%Loop

for rw = 1 : rs

%Find cost

invCost = invCost + (data(rw, 2) * data(rw, 3));

%Loop end

end

%Display the cost.

fprintf('Total cost: %4.2f\n\n', invCost);

Explanation:

RELAXING NOICE
Relax