Copy your temptbl.c file from your Lab4 directory into your Lab5 directory. Modi
ID: 3872124 • Letter: C
Question
Copy your temptbl.c file from your Lab4 directory into your Lab5 directory. Modify your temptable() function to be:
********note/question at bottom. Thank You
The new function, temptable(), should still use your function, tocelsius(). Its job is to print an appropriate temperature table. The catch is that this function should work correctly, regardless of whether the first temperature is larger than the second or the second is larger than the first. In addition, it should not behave badly (go into an infinite loop) with a very small step (such as 0.0); that means for this lab that it should produce an error message "No table--step smaller than 0.001!" if the step is smaller than 0.001. If the step is negative, the function should turn it into a positive step. The call
should produce this output:
The call
or the call
should produce this output:
Finally, replace the main program in temptbl.c with a new main program that repeatedly reads the temperatures and the step from the user and then uses the temptable function to print the table. As an example, here's a sample run of the program.
This is the file from temptbl.c
********This program needs help too. If possible, can you please help modify the original code before the modification of the new material. Thank you, im really struggling with this!
scanf("%d", degrees);
/* compute degreees in celcius from fahreneheit */
Celcius= ( Fahrenheit - 32) * (5/9);
/* Given: a temperature reading in degrees Fahrenheit Returns: the temperature in degrees Celsius */
/* Given: starting and ending temperatures in degrees Fahrenheit The function prints a table of conversions from degrees Fahrenheit to degrees Celsius from start to at most stop in five degree F increments, one conversion per line. Returns: the number of table lines printed. */
/* print results */
printf(" %d Celcius ");
printf();
}
Explanation / Answer
#include <stdio.h>
int temptable(float start, float stop, float step)
{
int i;
float celcius,fahrenheit;
printf(" Fahrenheit Celcius");
int count = 0;
for(i = start; i<=stop; i= i+step) //loop to print table
{
fahrenheit = i;
celcius= (fahrenheit - 32) * ((float)5/9); //conversion formula using typecasting (float) to retain decimal value
printf(" %.2f %.2f",fahrenheit,celcius);
count++;
}
printf(" Computed %d temperatures ",count);
}
int main(void) {
float start,stop;
int step;
printf("Enter start, stop and step:");
scanf("%f %f %d",&start,&stop,&step);
temptable(start,stop,step); //function call
return 0;
}
Output:
Enter start, stop and step:
Fahrenheit Celcius
32.00 0.00
36.00 2.22
40.00 4.44
44.00 6.67
48.00 8.89
52.00 11.11
56.00 13.33
60.00 15.56
64.00 17.78
Computed 9 temperatures 32 64 4