Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a script to calculate the volume of a pyramid, V = 1/3 * base * height, wh

ID: 3924371 • Letter: W

Question

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.

Explanation / Answer

% 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

%}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote