Q:

Write a script called prtemps that will prompt the user for a maximum Celsius value in the range from -16 to 20; error-check to make sure it’s in that range

0

 Write a script called prtemps that will prompt the user for a maximum Celsius value in the range from -16 to 20; error-check to make sure it’s in that range. Then, print a table showing degrees Fahrenheit and degrees Celsius until this maximum is reached. The first value that exceeds the maximum should not be printed. The table should start at 0 degrees Fahrenheit, and increment by 5 degrees Fahrenheit until the max (in Celsius) is reached. Both temperatures should be printed with a field width of 6 and one decimal place. The formula is C = 5/9 (F-32). 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

prtemps.m

% Prompt for a maximum C temperature and print a table

% showing degrees C and degrees F

fprintf('When prompted, enter a temp in degrees C in')

fprintf(' range -16\n to 20.\n')

maxtemp = input('Enter a maximum temp: ');

% Error-check

while maxtemp < -16 || maxtemp > 20

 maxtemp = input('Error! Enter a maximum temp: ');

end

% Print table include headers

fprintf(' F C\n');

f = 0;

c = 5/9*(f-32);

while (c <= maxtemp)

 fprintf('%6.1f %6.1f\n',f,c)

 f = f + 5;

 c = 5/9*(f-32);

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now