Re: whats wrong with my decimal input



TallGlass,

You didn't do quite enough scouring. You've defined "rate" as an
integer and read it in as such. Thus, there's no way scanf is going to
let you enter a decimal point in it. Change your definition "int
rate=0;" to "float rate=0.0F" and the line "scanf("%d",&rate)" to
"scanf("%f",&rate)" and things will work like you expect.
Somehow you must have been headed in this direction as you're
casting rate to a float in your computation.

-Jay

.



Relevant Pages

  • scanf to handle double
    ... Can someone please tell me how I should write scanf to handle double? ... This program works fine for float a but not double a, ... int main (void) ... Prev by Date: ...
    (comp.lang.c)
  • Re: scanf to handle double
    ... > Can someone please tell me how I should write scanf to handle double? ... > This program works fine for float a but not double a, ... > int main (void) ... Prev by Date: ...
    (comp.lang.c)
  • Re: scanf for char input getting skipped
    ... of discovering that scanf isn't as clever as he thought. ... float hours_worked = 0; ... Please enter the employee's clock number: ... Employee Clock Number Hourly Rate Hours Worked Gross ...
    (comp.lang.c)
  • Re: verify float number
    ... scanf returns the number of fields that it successfully read. ... field to be a float, it successfully read one float value. ... I need to verify that a number ... Boeing Associate Technical Fellow ...
    (comp.lang.c)
  • Re: Question for a REAL expert on casting double to float...
    ... out...I still have an outstanding question/confusion, ... Scanf actually treats "%d" as a signed integer. ... sscanf uses %f for a float rather than a double. ... version of the format specifiers) for the correct action, ...
    (comp.lang.c)

Loading