0

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


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?

1 Answers1

0

Change

float distance;
float noOfLiters;
Mert
  • 230
  • 1
  • 13