nodeffect
09-12-2004, 09:37 AM
#include <stdio.h>
int main()
{
char choose = 'a';
float celsius, fahrenheit;
printf( "***Temperature Conversion Calculator***\n" );
printf( "Enter a character[c for convert to Celsius, f for convert to Fahrenheit]: " );
scanf( "%c", &choose );
while ( choose != 'c' && choose != 'C' && choose != 'f' && choose != 'F' ){
scanf( "%c", &choose ); /* <-- WHY CAN'T I REMOVE THIS ? */
printf( "\n!!Error Message: Wrong input, please try again.\n" );
printf( "\nEnter a character[c for convert to Celsius, f for convert to Fahrenheit]: " );
scanf( "%c", &choose );
}
switch ( choose ) {
case 'c':
case 'C':
printf( "Enter the Fahrenheit value[in integer]: " );
scanf( "%f", &fahrenheit );
celsius = 5.0/9.0 * ( fahrenheit - 32 );
break;
case 'f':
case 'F':
printf( "Enter the Celsius value[in integer]: " );
scanf( "%f", &celsius );
fahrenheit = ( celsius / (5.0/9.0) ) + 32;
break;
}
printf( "\n***Temperature Conversion Calculator***\n" );
printf( "The result is:\n" );
printf( "%10s%10s\n", "Fahrenheit", "Celsius" );
printf( "%10.3f%+10.3f\n", fahrenheit, celsius );
return 0;
}
see "/* <-- WHY CAN'T I REMOVE THIS ? */" that line...
so why..? if i remove that scanf line, the while loop will repeat itselfs 2 times. I really don't understand !....Please help guys :(
int main()
{
char choose = 'a';
float celsius, fahrenheit;
printf( "***Temperature Conversion Calculator***\n" );
printf( "Enter a character[c for convert to Celsius, f for convert to Fahrenheit]: " );
scanf( "%c", &choose );
while ( choose != 'c' && choose != 'C' && choose != 'f' && choose != 'F' ){
scanf( "%c", &choose ); /* <-- WHY CAN'T I REMOVE THIS ? */
printf( "\n!!Error Message: Wrong input, please try again.\n" );
printf( "\nEnter a character[c for convert to Celsius, f for convert to Fahrenheit]: " );
scanf( "%c", &choose );
}
switch ( choose ) {
case 'c':
case 'C':
printf( "Enter the Fahrenheit value[in integer]: " );
scanf( "%f", &fahrenheit );
celsius = 5.0/9.0 * ( fahrenheit - 32 );
break;
case 'f':
case 'F':
printf( "Enter the Celsius value[in integer]: " );
scanf( "%f", &celsius );
fahrenheit = ( celsius / (5.0/9.0) ) + 32;
break;
}
printf( "\n***Temperature Conversion Calculator***\n" );
printf( "The result is:\n" );
printf( "%10s%10s\n", "Fahrenheit", "Celsius" );
printf( "%10.3f%+10.3f\n", fahrenheit, celsius );
return 0;
}
see "/* <-- WHY CAN'T I REMOVE THIS ? */" that line...
so why..? if i remove that scanf line, the while loop will repeat itselfs 2 times. I really don't understand !....Please help guys :(