double in C
I'm trying to write something simple in C and it doesn't work right.
Can someone help me with that code? #include <stdio.h> int main() { double num; char option; do { printf("Enter km/h: "); scanf("%f", &num); printf("%f\n", num); printf("%f m/s", num * 0.277777778); printf("\nDo you have another value (y/n)?"); scanf("%c%c", &option, &option); // scan twice -why? } while ( option == 'y'); puts("\nDone"); return 0; } I get this strange output: Enter km/h: 45 0.000000 0.000000 m/s Do you have another value (y/n)?n Done Program exited normally. Also when I scan for one character only the scanf() doesn't wait. I guess it read some \n character or something. Is there any way to fix it? thanks, |
|
thanks,
but also I was asking about double values that are not processed correctly. What am I doing wrong? |
With scanf() you should use the %lf modifier instead of %f with doubles.
|
All times are GMT -5. The time now is 07:38 PM. |