Issue
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?
Solution
Change
float distance;
float noOfLiters;
Answered By - Mert Answer Checked By - Willingham (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.