Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why I didn't get any floating points?

I am writing a program to calculate an average fuel consumption from the given total distance (integer value) traveled (in km) and spent fuel (in liters).

Code

#include <stdio.h>

int main(){
    int distance;
    int noOfLiters;
    printf("Enter The distance:");
    scanf("%d",&distance);
    printf("Enter The Fuel Spent:");
    scanf("%d",&noOfLiters);

    float avgFuelConsumption = noOfLiters/distance;

    printf("Average Fuel Consumption :  %f", avgFuelConsumption);
}

Output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


Enter The distance:50
Enter The Fuel Spent:5
Average Fuel Consumption :  0.000000

The Average Fuel Consumption should be 0.1, but I got 0, Why?

>Solution :

Change

float distance;
float noOfLiters;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading