Reputation: 2581
The code is:
#include <stdio.h>
#include <stdlib.h>
int main() {
double C, F;
printf("Enter the temperature in Celisius: ");
scanf("%f", &C);
F = 32 + (C * (180.0 / 100.0));
printf("%f C = %f F\n", C, F);
system("pause");
return 0;
}
The output is:
Enter the temperature in Celisius: 100
-92559604910177974000000000000000000000000000000000000000000000.000000 C = -166607288838320360000000000000000000000000000000000000000000000.000000 F
Upvotes: 1
Views: 76
Reputation: 134346
You got wrong conversion specifier there with double
for scanf()
. You need to use
scanf("%lf", &C);
To add the relevant quote, from C11
, chapter §7.21.6.2
l
(ell)Specifies that a following
d
,i
,o
,u
,x
,X
, orn
conversion specifier applies to an argument with type pointer tolong int
orunsigned long int
; that a followinga
,A
,e
,E
,f
,F
,g
, orG
conversion specifier applies to an argument with type pointer todouble
; or that a followingc
,s
, or[
conversion specifier applies to an argument with type pointer towchar_t
.
That said, you must check the return value of scanf()
to ensure the success of the call. Otherwise, you'll end up using the value of an uninitialized variable.
Upvotes: 4