2

I'm taking the input via

float f = GetFloat();

I enter 4.2 I multiply it by 100 and print the integer and I get 419.

This is my output

O hai!  How much change is owed?  
4.2  
n=419  
22

How do I fix this?

5

Use round() function of math.h.

#include <stdio.h>
#include <cs50.h>
#include <math.h>

int main(void)
{
    float f = GetFloat();
    int value = round(f * 100);

    printf("%d", value);
}

For input: 4.2

Output: 420

2
  • thanks that did it
    – user1291
    Jun 14 '14 at 17:40
  • Thanks. I got it
    – user1303
    Jun 15 '14 at 6:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .