Mail Archives: djgpp/1993/01/08/10:59:48
> (In cases like this, it is hard to tell what he meant...)
>
> >Richard Shields <src4src!mcdhup!rutgers!sequent.com!richards> writes:
>
> >>
> >> Has anyone had any trouble using scanf to read in a floating point value?
> >>
> >> I tried this in my code:
> >>
> >> double amount;
> >>
> >> scanf("%f", amount);
In the reference manual, amount should be &amount, i.e. the address
of the variable.
> >> printf("amount = %10.2f\n", amount);
> >>
> >>
> >> When I run the program and enter 4.25 the printf statement prints 0.00.
> >>
>
> >You told scanf to read in a "float", not a "double". Need to say "%lf".
>
> Maybe he meant to declare amount as float.
>
> Also, the program would probably work if he put a star after the comma
> in the printf() call. (Kids, don't try this at home...)
>
I hope this helps
John
---------------------------------------------------------------------
Dr John P. Fletcher
Department of Chemical Engineering and Applied Chemistry,
Aston University, Tel: (44) 21 359 3611 ext 4625
Aston Triangle, Email(Most systems): J DOT P DOT FLETCHER AT ASTON DOT AC DOT UK
BIRMINGHAM B4 7ET U.K. Email(JANET only): J DOT P DOT FLETCHER AT UK DOT ASTON DOT AC
---------------------------------------------------------------------
- Raw text -