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

When you received your first water bill, you noticed that the water price per ga

ID: 2318758 • Letter: W

Question

When you received your first water bill, you noticed that the water price per gallon varies based on consumption. The price per gallon of water is $.72 for the first 5000 gallons, $1.35 for the next 2000 gallons, and $2.25 for all gallons in excess of 7000 gallons Write a MATLAB program that determines the total amount of the bill (totalp) and the average price per gallon (avgp) for a given number of gallons Make sure that the program prompts the user to enter the number of gallons of water used Display the two results totalp and avgp.

Explanation / Answer

clear;

clc;

n = input('Enter No. of gallons Consumed: ');

if(n < 0)

disp('Invalid number. Enter positive number');

else

if(n <= 5000)

total = n*0.72;

elseif(n <= 7000)

total = (5000*0.72) + ((n-5000)*1.35);

else

total = (5000*0.72) + (2000*1.35) + ((n-7000)*2.25);

end

fprintf('The total amount of bill (totalp) = %f ', total);

fprintf('Average price per gallon (avgp) = %f ', total/n);

end

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