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

This is what I have , but the conversion is wrong and I cannot enter single inte

ID: 3530939 • Letter: T

Question

This is what I have , but the conversion is wrong and I cannot enter single integers. Please help! /* This program converts temperatures from Farenheit to Celsius. Written by: Tom Carey Date: 03/16/2013 */ #include#includeint main() { // Local Declaration float fh,cl; char ch; // Statements printf("Converts temperature from Farenheit to Celsius Enter a number or Q to quit: "); while (getchar() != 'Q') { scanf("%f", &fh); cl = ((fh-32.0)/1.8); getchar(); printf("Converted Celsius value: %.2f ",cl); printf(" Enter a number or Q to quit: "); } printf("Goodbye "); return (0); } //main

Explanation / Answer

include<stdio.h>
int main()
{
int fahr,cel,choice;

printf("What do you want to do?(1/2) 1. fahrenheit to Celsius 2. Celsius to Fahrenheit ");
scanf("%d",&choice);

switch(choice)
{
case 1:
printf("Enter fahrenheit value ");
scanf("%d",&fahr);
cel=(fahr-32)*5/9;
printf("Celsius of %d degrees fahrenheit is %d degrees celsius ",fahr,cel);

case 2:
printf("Enter fahrenheit value ");
scanf("%d",&cel);
fahr=cel*5/9 + 32;
printf("Fahrenheit of %d degrees Celsius is %d degrees fahrenheit ",cel,fahr);
}
}



OR (same program replacing the switch with if statements)


#include<stdio.h>
int main()
{
int fahr,cel,choice;

printf("What do you want to do?(1/2) 1. fahrenheit to Celsius 2. Celsius to Fahrenheit ");
scanf("%d",&choice);


if(choice==1)
{
printf("Enter fahrenheit value ");
scanf("%d",&fahr);
cel=(fahr-32)*5/9;
printf("Celsius of %d degrees fahrenheit is %d degrees celsius ",fahr,cel);

}

if(choice==2)
{
printf("Enter fahrenheit value ");
scanf("%d",&cel);
fahr=cel*5/9 + 32;
printf("Fahrenheit of %d degrees Celsius is %d degrees fahrenheit ",cel,fahr);
}

}

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