Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, I\'m taking a programming class where I am leanring C. I need help on an ass

ID: 3880115 • Letter: H

Question

Hi,

I'm taking a programming class where I am leanring C. I need help on an assignment which is called Temperature Conversion in C. I have attached the assignment below. I am trying to work on the if statements but I'm not sure how to write them correctly. Thanks!

Here is what I have so far:

#include

int main (void){
float farhenheit,celsius,kelvin;
float num;
char cha;
printf("Please enter a temperature:");
/* reading in the number plus the one letter so it cant be %f
*/
scanf("%f %c",&num,&cha);

if(cha=='c'){
return float farhenheit = 9/5(kelvin-273.15)+32;
return float kelvin = celsius + 273.15;
}
if(cha=='f'){
return float celsius = (farhenheit-32)/1.8;
return float kelvin=celsius + 273.15;
}
if(cha=='k'){
return float celsius = (farhenheit-32)/1.8;

/*if the input is celsius then convert it to fahrenheit and kelvin
*if its kelvin, convert to celsius and fahrenheit
*if its fahrenheit, convert to celsius and kelvin
*if input is not the proper value print invalid temp scale and return non-0

Assignment 3: Temperature conversion in C Due date: Sunday, 10 September 2017, 11:55 PM Maximum number of files: 1 Type of work: Individual work Assignment Write a program in C that converts temperatures between Fahrenheit, Celsius, and Kelvin. Functional Requirements MUST correctly convert temperatures between scales MUST read input by prompting the user Nonfunctional Requirements MUST compile without warnings and errors MUST print error message "Invalid temperature scale" on invalid input .MUST return O on success MUST return non-O value on failure Sample run $ ./temp Enter input temperature: 18c 18.00 C converts tO: 64.40 F 291.15K The conversion formulas are listed below: Celsius - (Fahrenheit 32)/1.8 Kelvin = Celcius + 273.15 NOTE: The converted temperatures are indented by tabs.

Explanation / Answer

#include <stdio.h> // headerfile

int main() // main function
{

float f,c,k; // declaring float values
int ch;

printf(" 1: Convert temperature from Fahrenheit to Celsius."); // user interface
printf(" 2: Convert temperature from Celsius to Fahrenheit.");
printf(" 3: Convert temperature from kelvin to Celsius.");

printf(" Enter your choice (1,2,3): ");
scanf("%d",&ch);

if(ch ==1) // right way to use 'if-else' ladder
printf(" Enter temperature in Fahrenheit. ");
scanf("%f",&f);
c= (f - 32) / 1.8;
printf("Temperature in Celsius: %.2f",c);
}
else if(ch==2){
printf(" Enter temperature in Celsius. ");
scanf("%f",&c);
f= (c*1.8)+32;
printf("Temperature in Fahrenheit: %.2f",f);
}
else if(ch==3){
printf(" Enter temperature in Kelvin. ");
scanf("%f",&c);
k= c+273.15;
printf("Temperature in Celsius: %.2f",k);
} else
{
printf(" Invalid Choice");
}
return 0; //return truee or 0
}

thank you

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote