Hi! I am new to C programming and I just cannot figure out how to continue on my assignment. I am not asking for people to do my homework I just need a nudge in the right direction. I am trying to calculate miles per gallon from what the user inputs into the program but only tells me a number if I input large numbers and if I put in smaller numbers such as 40, 35, .8 It tells me that I averaged 00 miles per hour.
I am guessing it's something wrong with my calculation of miles per hour. Sorry for such a stupid question but I'm stumped.Code:#include <stdio.h> #define MINUTES_IN_HOUR 60 int main(void) { //Declare variables int minutes, average_speed, gallons, mpg; //Prompt for user to enter data printf("How many minutes did you drive?\n"); scanf("%d", &minutes); printf("What was the average speed of the car during that time?\n"); scanf("%d", &average_speed); printf("How many gallons of gas did your car use?\n"); scanf("%d", &gallons); //Use user data to calculate the miles per gallon mpg = ((minutes/MINUTES_IN_HOUR)*(average_speed))/gallons; printf("Your car averaged %.2d miles per gallon.\n", mpg); system("pause"); return 0; }



LinkBack URL
About LinkBacks



