/* Program 3: This program will estimate expenses for a round-trip car trip, focusing on gas costs. */ /* Author: Nicholas Della Vecchia */ /* Date: 2/01/01 */ #include int main() { /* variable decleration section */ /* define variable for the number of miles between cities */ double numbermiles; /* define variable for expected number of miles per hour */ double milesperhour; /* define variable for expected miles per gallon */ double milespergallon; /* define variable for expected cost per gallon */ double costpergallon; /* define variable for gallons */ double gallons; /* define variable for price */ double price; /* define variable for the cost of the trip */ double cost; /* define variable for the total round trip miles */ double roundtrip; /* define variable for the actual miles per gallon on the trip */ double tripmpg; printf ("Welcome to the Fuel Cost Estimator Program\n\n\n"); /* variable assignments */ /* input from the user the value of numbermiles */ printf ("Please enter the number of miles between cities: "); scanf ("%lf",&numbermiles); /* input from the user the value of milesperhour */ printf ("\nPlease enter the expected miles per hour: "); scanf ("%lf",&milesperhour); /* input from the user the value of milespergallon */ printf ("\nPlease enter expected miles per gallon: "); scanf ("%lf",&milespergallon); /* input from the user the value of costpergallon */ printf ("\nPlease enter the expected cost per gallon: "); scanf ("%lf",&costpergallon); printf ("\n\n\n"); /* Calculations */ /* Calculate the total miles for a round trip */ roundtrip = (numbermiles * 2); /* Calculation if speed is over 50 miles/hour, then the miles per gallon increases by 10% */ if (milesperhour > 50) tripmpg = ((milespergallon * .10) + milespergallon); else tripmpg = milespergallon; /* Calculate the actual gallons used on the trip */ gallons = (roundtrip/tripmpg); /* Calculate the cost of the whole trip */ cost = (costpergallon * gallons); /* Results */ printf ("===============================================================================\n\n\n"); printf ("Estimate for Customer:\n\n"); printf ("Miles: One way: %0.2f \n", numbermiles); printf (" Round Trip: %0.2f \n\n", roundtrip); printf ("Mpg: City: %0.2f \n", milespergallon); printf (" Trip: %0.2f \n\n", tripmpg); /* Show user the final gallons used on trip and price of trip */ printf ("Gallons: %0.2f \n", gallons); printf ("Price: %0.3f \n", costpergallon); printf ("Cost: %0.2f \n\n\n", cost); printf ("===============================================================================\n\n\n"); }