Ok, so the program is supposed to take in an initial mile odometer reading. Subtract that number from a new odometer reading at time of refueling and divide that difference by the amount of gas needed to fill the car up. Resulting in MPG for that segment of trip.
Here is what I got so far:
So right now this is what I am getting after running with no compiler issues...Code:#include <stdio.h> #define CUTOFF -1 int main() { float gas; int sMileage, fMileage, tMileage, mpg; printf("\nThis program will calculate your Miles Per Gallon(MPG) between two distances."); printf("\nTo stop entering data, type a negative number for input"); printf("\nor simotaneusly press ctrl+Z(Windows) or ctrl+D(Unix) to stop."); while (sMileage > CUTOFF || fMileage > CUTOFF || gas > CUTOFF){ printf("\nEnter starting trip mileage"); scanf("%d", &sMileage); printf("\nEnter end of trip mileage"); scanf("%d", &fMileage); printf("\nEnter amount of gas needed to refeul vehicle"); scanf("%.2f", &gas); tMileage = (fMileage - sMileage); } mpg = gas / tMileage; printf("\nyour MPG for trip distance entered was %.2f, mpg"); return 0; }
After the first run of the loop it completely skips the "scanf" to enter the starting tirp mileage and goes straight to end of trip mileage, also the sentinel doesn't work and it just keeps cycling.[cameron@localhost Program5]$ ./Exercise10
This program will calculate your Miles Per Gallon(MPG) between two distances.
To stop entering data, type a negative number for input
or simotaneusly press ctrl+Z(Windows) or ctrl+D(Unix) to stop.
Enter starting trip mileage5
Enter end of trip mileage10
Enter amount of gas needed to refeul vehicle2
Enter starting trip mileage
Enter end of trip mileage5
Enter amount of gas needed to refeul vehicle10
Enter starting trip mileage
Enter end of trip mileage2
Enter amount of gas needed to refeul vehicle-1
Enter starting trip mileage
Enter end of trip mileage-1
Enter amount of gas needed to refeul vehicle-1
Enter starting trip mileage
I was kind of shooting to give mpg results and then go back to entering in the initial trip mileage where the user could deside to terminate.
Also ctrl+d doesn't work for me on Fedora.