Write a script to calculate the volume of a pyramid V 13 b

Write a script to calculate the volume of a pyramid, V = 1/3 * base * height, where base = length * width. Prompt the user to enter values for the length, width and height of the pyramid. When the user enters each value, he or she will then be prompted for either i for inches or c for centimeters. The script should then calculate the volume and then print the volume in cubic inches with three decimal places. As an example, the format will be: Enter the length of the base: 50 Is that i or c? i Enter the width of the base: 6 Is that i or c? c Enter the height: 4 Is that i or c? i The volume of the pyramid is xxx.xxx cubic inches.

Solution

% matlab code to determine the volume

length = input(\"Enter the length of the base: \");
choice = input(\"Is that i or c? \", \'s\');
if choice == \'c\'
    length = length/2.54;
end
width = input(\"Enter the width of the base: \");
choice = input(\"Is that i or c? \", \'s\');
if choice == \'c\'
    width = width/2.54;
end
height = input(\"Enter the height: \");
choice = input(\"Is that i or c? \", \'s\');
if choice == \'c\'
    height = height/2.54;
end

volume = (1/3)*length*width*height;
fprintf(\"The volume of the pyramid is %0.3f cubic inches\ \",volume);

%{
output:

Enter the length of the base: 50
Is that i or c? i             
Enter the width of the base: 6
Is that i or c? c             
Enter the height: 4           
Is that i or c? i             
The volume of the pyramid is 157.480 cubic inches

%}

 Write a script to calculate the volume of a pyramid, V = 1/3 * base * height, where base = length * width. Prompt the user to enter values for the length, widt

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site