How do i call a value from a matrix based on an input?

1 view (last 30 days)
My program must calculate the total cost by using the variable PN to select the correct part cost in the parts cost matrix PC. The total cost is the number of parts multiplied by the cost of each part.
How would I go about completing this?
So far I have this.
clc
clear
PC=[1741 2377 3203 3571;0.37 0.21 0.31 0.17];%first row indicates the part number. Second row corresponds to the cost of each part.
C=input('Enter company name: ','s');
PN=menu('Select a part number',PC(1,1),PC(1,2),PC(1,3),PC(1,4));
Q=input('Enter quantity of the selected part: ');
fprintf('An order has been placed by %s for %d parts.',C,Q);
fprintf('Each part costs %0.1f.',
Also, im not sure if there is a better way of writing out the following statement:
PN=menu('Select a part number',PC(1,1),PC(1,2),PC(1,3),PC(1,4));
Thanks in advance.

Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!