Wednesday
August 5, 2015

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

More Related Questions

Members