Thursday
September 18, 2014

Homework Help: C Programming

Posted by gnozahs on Tuesday, September 29, 2009 at 12:50am.

Okay, question.

What if I inputted this:
Enter a temperature: 32
Enter 'C' for Celsius or 'F' for Fahrenheit: c
Choose a conversion ('C' for Celsius or 'F' for Fahrenheit): c
The temperature is: 0.0 C.

I want the program to read [The temperature is: 32 C.] when I go from C to C but my program is outputting 0.0 C. Same thing when I go from F to F.

CODE:
/* Directives */

#include <stdio.h>

int main(void)
{

float temp, CtoF, FtoC;
char choic;
char choice;
char answer[10];
char answers[10];
printf("Enter a temperature: ");
scanf("%f", &temp);

printf("Enter 'C' for Celsius or 'F' for Fahrenheit: ");

scanf("%s", answer);
choic=answer[0];

switch(choic)
{
case 'F':
case 'f':
{
break;
}

case 'C':
case 'c':
{
break;
}

default:
{printf("Unknown Syntax!\n");
return(0);
break;
}
}


printf("Choose a conversion ('C' for Celsius or 'F' for Fahrenheit): ");


scanf("%s", answers);
choice=answers[0];

switch(choice)
{
case 'F':
case 'f':
{CtoF = temp*9/5+32;
printf("The temperature is: %.1f F.\n", CtoF);
break;
}
case 'C':
case 'c':
{FtoC = (temp - 32) * (5.0/9.0);
printf("The temperature is: %.1f C.\n", FtoC);
break;
}

default:
{printf("Unknown Syntax!\n");
return(0);
break;
}
}





/* End Program */
return(0);

}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

C Programming - This is what the program needs to do: Enter a temperature: 32.4 ...
C Programming - Write a program that prompts the user to enter a temperature, ...
Algebra - The folrmula F=9/5c+32 can be used to make temperature conversions ...
Fund of programming 1 - Complete the following C++ program. The program should ...
computer science - in one the chapter 3 programming challenges you were asked to...
math - Consider the following method of estimating Fahrenheit temperatures given...
Algebra - Celsius temperature readings can be converted to Fahrenheit readings ...
Algebra - In order to covert temperature from Celsius to Fahrenheit,one can use ...
chemistry - Rank the size of a change in temperature of one degree fahrenheit, ...
math - the formula C=5/9(F-32) is used to convert Fahrenheit temperature,F, to ...

Search
Members