Answer:
Here is the code in c++.
//include headers
#include <bits/stdc++.h>
using namespace std;
int main() {
//variables to store input
float dis,fuel_effi,price_gall;
cout<<" Enter total distance of the trip: ";
//read distance
cin>>dis;
cout<<" fuel efficiency of car( miles per gallon):";
//read fuel efficiency
cin>>fuel_effi;
cout<<" price of fuel (per gallon):";
//read price of fuel
cin>>price_gall;
// calculate total cost of trip
float tot_cost=dis*price_gall/fuel_effi;
cout<<"Total cost of the trip is: "<<tot_cost<<endl;
return 0;
}
Step-by-step explanation:
First read distance to travel, fuel efficiency of the car and price of fuel per gallon.To find the total cost of the trip, we use the formula total cost=dis*price_gall/fuel_effi. Where "dis" is total distance of trip, "price_gall" is price of fuel per gallon and "fuel_effi" is fuel efficiency of the car. The mentioned formula gives the total cost of the trip.
Output:
Enter total distance of the trip: 120
fuel efficiency of car( miles per gallon):30
price of fuel (per gallon):100
Total cost of the trip is: 400