Write a program that will first allow a user to choose one of two options: 1. Co
ID: 3779914 • Letter: W
Question
Write a program that will first allow a user to choose one of two options: 1. Convert a temperature from degrees Celsius to degrees Fahrenheit. 2. Convert a temperature from degrees Fahrenheit to degrees Celsius.
The program should then prompt for the temperature value to be entered and output the new value that results from the conversion. To convert from Celsius to Fahrenheit you can multiply the value by 1.8 and then add 32. To convert from Fahrenheit to Celsius, you can subtract 32 from the value, then multiply by 5, and divide the result by 9.
Screen Output Examples:
degree C to degree F
This program can do the following: 1. Convert from degrees Centigrade to degrees Fahrenheit 2. Convert from degrees Fahrenheit to degrees Centigrade Select the conversion (1 or 2): Enter a temperature in degrees Centigrade: That is equivalent to 50.5 degrees Fahrenheit
degree F to degree C
This program can do the following: 1. Convert from degrees Centigrade to degrees Fahrenheit 2. Convert from degrees Fahrenheit to degrees Centigrade Select the conversion (1 or 2): Enter a temperature in degrees Fahrenheit: That is equivalent to 120 degrees Centigrade
USE THE DEFAULT CODE TO WRITE THE SOLUTION AND DO NOT MODIFY THE DEFAULT TEMPELATE. WRITE THE CODE IN C.
GIVEN CODE:
/* Exercise 1 Convert temperatures */
#include <stdio.h>
int main(void)
{
int choice = 0;
double temperature = 0.0;
printf("This program can do the following: "
"1. Convert from degrees Centigrade to degrees Fahrenheit "
"2. Convert from degrees Fahrenheit to degrees Centigrade "
"Select the conversion (1 or 2): ");
scanf("%d", &choice);
// Your Code Here
if (choice ==1){
printf("Enter Temprature Value");
scanf("%lf", &temperature);
temperature = (temperature * 1.8)+ 32;
printf("Fahrenheit:%lf",temperature);
}
if(choice==2){
printf("Enter Temprature Value:");
scanf("%lf", &temperature);
temperature = ((temperature-32)*5)/9;
printf("Celsius:%lf", temperature);
}
return 0;
}
Explanation / Answer
PROGRAM CODE:
#include <stdio.h>
int main(void)
{
int choice = 0;
double temperature = 0.0;
printf("This program can do the following: "
"1. Convert from degrees Centigrade to degrees Fahrenheit "
"2. Convert from degrees Fahrenheit to degrees Centigrade "
"Select the conversion (1 or 2): ");
scanf("%d", &choice);
if (choice ==1){
printf(" Enter Temperature in degrees centigrade: ");
scanf("%lf", &temperature);
temperature = (temperature * 1.8)+ 32;
printf(" That is equivalent to %lf degrees Fahrenheit",temperature);
}
if(choice==2){
printf(" Enter Temperature in degrees Fanrenheit: ");
scanf("%lf", &temperature);
temperature = ((temperature-32)*5)/9;
printf(" That is equivalent to %lf degrees Centigrade", temperature);
}
return 0;
}
OUTPUT:
Run # 1
Run # 2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.