0

When i enter 0.2 as the volume i should get 2260.00 but im getting 2260.001 and i cant understand why. Even after adjusting how many decimals i want there is always 0.1 at the end...

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int option;
    float volume;
    float density = 11300;
    float mass;

    while (option != 3)
    {
        printf("1: Calculate Mass\n");
        printf("2: Calculate Volume\n");
        printf("3: Exit\n");
        printf("Input here: ");
        scanf("%d", &option);

        if (option == 1)
        {
            printf("Input Volume: ");
            scanf("%f", &volume);

            mass = volume*density;
            printf("%.2f", mass);
        }

    }

   return 0;
}
xxFlashxx
  • 261
  • 2
  • 13

0 Answers0