PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 24, 2022

[FIXED] why I didn't get any floating points?

 October 24, 2022     c, decimal, printf, scanf     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing