Question

In: Computer Science

MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases...

MUST BE DONE IN C (NOT C++)

Your create a program that can implement the cases in which the initial unit is Fahrenheit or something not recognizable. Your program should incorporate Fahrenheit to Celsius, Fahrenheit to Kelvin and unknown initial units (display an error message for this last one). You must use functions to calculate Fahrenheit degrees.

Solutions

Expert Solution

#include<stdio.h>
//function to convert from fahrenheit to kelvin
float FahrenheitToKelvin(float temperature)
{
    float kelvin;
    //expression to convert fahrenheit to kelvin
    kelvin = (temperature-32)*(float)5/9+273.15;
    return kelvin;//return kelvin
}
//function to convert from fahrenheit to celcius
float FahrenheitToCelcius(float temperature)
{
   float celcius;
       //expression to convert fahrenheit to celcius
   celcius = (temperature - 32)*(float)5/9;
   return celcius;//return celcius
}
//driver program
int main()
{
    //variable declarations
    float celcius,kelvin,fahrenheit;
    int opt;
    printf("\n Enter the temperature in Fahrenheit");
    scanf("%f",&fahrenheit); //read the temperature in fahrenheit
    //show the options
    printf("\n 1. Fahrenheit to Kelvin.\n 2. Fahrenheit to Celcius.");
    printf("\n Enter the choice : ");
    scanf("%d",&opt);//read the option
    //condition to call FahrenheitToKelvin(fahrenheit);
    if(opt==1)
    {
       kelvin = FahrenheitToKelvin(fahrenheit);
       printf("\n%5.1f F = %5.3f K",fahrenheit,kelvin);
       }
       else
       //condition to call FahrenheitToCelcius(fahrenheit);
       if(opt==2)
           {
       celcius = FahrenheitToCelcius(fahrenheit);
       printf("\n%5.1f F = %5.3f K",fahrenheit,celcius);
           }
           else//block for invalid choice
           printf("\n ERROR : Invalid Choice for conversion.");
   return 0;
}

output


Related Solutions

(MUST BE DONE IN C (NOT C++)) In this task, you will create a structure with...
(MUST BE DONE IN C (NOT C++)) In this task, you will create a structure with arrays. You will have to create your own structure. However, make sure to meet these guidelines: - Give the structure whichever name you want. - It must have at least 3 members. - Two of the members must be arrays. - Your members should be of at least two different data-types. In other words, your members cannot be integers only (or floats, or doubles…)....
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of x students’ grades (grades will be stored in an array). To do so, please follow these guidelines: - Your program should ask the user for the number of students that are in the class. This number should help you declare your array. - Use the function seen in class to scan the grades of the array. In other words, we will populate the array...
MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a...
MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a university’s profile (you can pick any university name, just so long as the program runs properly). The structure must contain 5 members: - One member for number of undergraduate students - One member for number of graduate students - One member for number of classrooms - One member for the name of the university (an array) - One member for the term (fall, summer...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to experiment with pointers. Implement the following steps one by one in your program: YOU NEED TO ANSWER QUESTION Use printf to print your answers at the end(after 12). 1. Declare three integer variables a, b and c. Initialize them to 0, 100 and 225, respectively. 2. Print the value of each variable and its address. 3. Add the following declaration to your code: int...
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches....
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches. First, ask the user for the name of students they have in their class. Then, using a loop, you will ask for each student’s height. However, you will have to use two separate variables, one for feet and one for inches. Then, you will have to call two functions. The first function will check if the values entered are valid (check if number of...
MUST BE DONE IN C (NOT C++) This program should utilize the basics of strings. First,...
MUST BE DONE IN C (NOT C++) This program should utilize the basics of strings. First, declare and initialize a string. You can name the variable whichever way you want and you can initialize it to whichever value you want. Then, use a for loop to print its characters; one at a time, until you reach the null character. After this, go ahead and declare a second string (since you are not initializing it right away, you will have to...
Must be done in C Write a C program found out the maximum value between the...
Must be done in C Write a C program found out the maximum value between the three numbers? Show steps with comments or else it will be flagged.
Write and test a C program to implement Bubble Sort. . In your C program, you...
Write and test a C program to implement Bubble Sort. . In your C program, you should do: Implement the array use an integer pointer, get the size of the array from standard input and use the malloc function to allocate the required memory for it. Read the array elements from standard input. Print out the sorted array, and don’t forget to free the memory. Debug your program using Eclipse C/C++ CDT.
(MUST BE DONE IN C (NOT C++)) Define two different structures at the top of your...
(MUST BE DONE IN C (NOT C++)) Define two different structures at the top of your program. Define each structure with exactly three members (each member has to be a different datatype). You may set them up whichever way you want. Don’t forget your semicolons. - Inside main, declare two structures. One for each of the two structures you defined. - Then, initialize each one of the members manually (the three members of your first structure and the three elements...
Calculations must be done in Excel – You must create your own spreadsheet do not copy...
Calculations must be done in Excel – You must create your own spreadsheet do not copy and paste someone else’s. Polycorp Limited Steel Division is considering a proposal to purchase a new machine to manufacture a new product for a potential three year contract. The new machine will cost $1.9 million. The machine has an estimated life of three years for accounting and taxation purposes. Installation will cost a further $120,000. The contract will not continue beyond three years and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT