Question

In: Computer Science

C language <stdio.h> (functions) Write a program to display a table of Fahrenheit temperatures and their...

C language <stdio.h> (functions)

Write a program to display a table of Fahrenheit temperatures and their equivalent Celsius temperatures. Create a function to do the conversion from Fahrenheit to Celsius. Invoke the function from within a for loop in main() to display the table. Ask the user for a starting temperature and and ending temperature. Validate that the starting temperature is within the range of -100 to 300 degrees, Validate that the ending temperature is in the range of -100 to 300 degrees, and is also greater than the starting temperature. Use a decision inside the ending temperature validation loop to display either the "out-of-range" message or the "greater than starting temperature" message.

The formula for converting a Fahrenheit temperature to Celsius is:
C = (5 / 9) * (F - 32)
Use this exact formula - do not pre-calculate 5/9 as .56 (you will have to type cast one of the numbers to a double for the equation to work correctly).

Format the Celsius temperatures to 1 decimal place.

Example Run #1:
(bold type is what is entered by the user)

Enter a starting Fahrenheit temperature: -200
The starting temperature must be between -100 and 300 degrees.
Please re-enter the starting temperature: 0
Enter an ending Fahrenheit temperature: 500
The ending temperature must be between -100 and 300 degrees.
Please re-enter the ending temperature: -20
The ending temperature, -20, must be greater than the starting temperature.
Please re-enter the ending temperature: 20

Fahrenheit Celsius
0 xx.x
1 xx.x
2 xx.x
3 xx.x
4 xx.x
5 xx.x
6 xx.x
7 xx.x
8 xx.x
9 xx.x
10 xx.x
11 xx.x
12 xx.x
13 xx.x
14 xx.x
15 xx.x
16 xx.x
17 xx.x
18 xx.x
19 xx.x
20 xx.x

The example run shows EXACTLY how your program input and output will look.

Solutions

Expert Solution

SOURCE CODE

#include <stdio.h>

int main()
{
float c, f1=500, f2=500;
int f;
printf("Enter a starting Fahrenheit temperature: ");
while(f1 < -100 || f1 > 300)
{
  
scanf("%f", &f1);
if( f1 < -100 || f1 > 300)
{
printf("The starting temperature must be between -100 and 300 degrees.\n");
printf("Please re-enter the starting temperature: ");

}
}
printf("Enter an ending Fahrenheit temperature : ");
while(f2 < -100 || f2 > 300 || f2 < f1)
{

scanf("%f", &f2);
if( f2 < -100 || f2 > 300)
{
printf("The ending temperature must be between -100 and 300 degrees.\n");
printf("Please re-enter the ending temperature: ");

}
if( f1 > f2)
{
printf("The ending temperature, %.0f, must be greater than the starting temperature.\n",f2);
printf("Please re-enter the ending temperature: ");

}
}
  
for(f=f1; f<=f2; f++)
{
c = (float)(f - 32) * 5 / 9;
printf("%d %.1f \n", f, c);
}
return 0;
}

SCREENSHOT

please give a upvote if u feel helpful.


Related Solutions

Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents....
Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents.  The formula for converting a temperature from Celsius to Fahrenheit is F = 9/ 5 C + 32 where F → Fahrenheit temperature C → Celsius temperature.  Allow the user to enter the range of temperatures in Celsius to be converted into Fahrenheit.  Your program must use a loop to display the values of the temperature conversions (see sample output). Sample...
*In C++ language please* Create a table that converts temperatures from Celsius to Fahrenheit Ask the...
*In C++ language please* Create a table that converts temperatures from Celsius to Fahrenheit Ask the user if they would like to know today's temperatures When "yes": Ask or their name -Generate a random number: use the length of their name (nameLngth) to set the seed Use the length of their name (nameLngth) as the starting point, and 99 as the ending point for a range of Celsius temperatures Output the range of Celsius temperatures alongside the Fahrenheit temperature conversions...
Write a program that prints a custom conversion table from Celsius temperatures to Fahrenheit and Newton...
Write a program that prints a custom conversion table from Celsius temperatures to Fahrenheit and Newton (Links to an external site.) temperatures. The formula for the conversion from Celsius to Fahrenheit is : F=9/5*C+32 F is the Fahrenheit temperature, and C is the Celsius temperature. The formula for the conversion from Celsius to Newton is C = 100/33*N N is the Newton Temperature and C is the Celsius temperature Your C++ program should prompt the user for a lower value...
C language <stdio.h> use double and const Write a program that asks the user for the...
C language <stdio.h> use double and const Write a program that asks the user for the radius of a circle (as a double) and displays the diameter, circumference, and area of the circle. Use a constant of 3.14159 as the value of pi. Have a blank line between the input and the output. Follow the 3 steps in the Information Processing Cycle - Input, Processing, and Output. The formulas needed are: diameter = 2 * radius circumference = 2 *...
LANGUAGE: C Only using <stdio.h> & <stdlib.h> Write a program that gives the user a menu...
LANGUAGE: C Only using <stdio.h> & <stdlib.h> Write a program that gives the user a menu to choose from – 1. Convert temperature input from the user in degrees Fahrenheit to degrees Celsius 2. Convert temperature input from the user in degrees Celsius to degrees Fahrenheit 3. Quit. Formulae you will need: C = (5 / 9) * (F-32) and F = (9/5) * C + 32 1. Use functions to accomplish 1 and 2 above. 2. Use at least...
IN C++: Write a program to display the following table. MUST use for-loop Enter the table...
IN C++: Write a program to display the following table. MUST use for-loop Enter the table size: 10 N N^2 Square root of N --------------------------------------------- 1 1 1.00 2 4 1.41 3 9 1.73 ….. 10 100 3.16
C language <stdio.h> ONLY USE double and const int Write a program to convert Celsius temperature...
C language <stdio.h> ONLY USE double and const int Write a program to convert Celsius temperature to Fahrenheit temperature. The formula for converting Celsius temperature into Fahrenheit temperature is:    F = (9 / 5) * C + 32 Create integer constants for the 3 numbers in the formula (9, 5, and 32).  Follow the 3 steps in the Information Processing Cycle - Input, Processing, and Output. Convert the 9 to a double when converting the temperature (use type casting). Have a...
Write the below C program using ARM assembly language and compile for Cortex A53. #include<stdio.h> void...
Write the below C program using ARM assembly language and compile for Cortex A53. #include<stdio.h> void quicksort(int number[25],int first,int last){ int i, j, pivot, temp; if(first<last) { pivot=first; i=first; j=last; while(i<j) { while(number[i]<=number[pivot]&&i<last) i++; while(number[j]>number[pivot]) j--; if(i<j){ temp=number[i]; number[i]=number[j]; number[j]=temp; } } temp=number[pivot]; number[pivot]=number[j]; number[j]=temp; quicksort(number,first,j-1); quicksort(number,j+1,last); } } int main() { int i, count, number[25]; printf("Enter some elements (Maximum 25): "); scanf("%d",&count); printf("Enter %d elements: ", count); for(i=0;i<count;i++) scanf("%d",&number[i]); quicksort(number,0,count-1); printf("The Sorted Order is: "); for(i=0;i<count;i++) printf(" %d",number[i]); return...
Write a program in C++ to display the multipliaction table vertically from 1 to n (use...
Write a program in C++ to display the multipliaction table vertically from 1 to n (use setw to format the output). 1x1 = 1, 2x1 = 2, 3x1 = 3, 4x1 = 4, 5x1 = 5, 6x1 = 6, 7x1 = 7, 8x1 = 8 ... 1x10 = 10, 2x10 = 20, 3x10 = 30, 4x10 = 40, 5x10 = 50, 6x10 = 60, 7x10 = 70, 8x10 = 80
TASK: Using stack functions, write a program in C++ language that acts as a simple calculator,...
TASK: Using stack functions, write a program in C++ language that acts as a simple calculator, reading an infix algebraic expression with numbers and simple operations: +, -, *, / , (, and ). The program converts an infix expression into an equivalent postfix expression, and then evaluates the postfix expression, and then prints the result if input expression is correct otherwise prints error messages. Your program must interact with the user until the user quits.    REQUIREMENTS: - Your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT