May 4, 2013 at 9:59pm UTC
My question is what data type should I use to get the miles_per_gallon to show only four decimal places? I have tried int, double, and float and they all give
#include<iostream>
using namespace std;
int main()
{
double miles;
double liters;
double gallons;
double miles_per_gallon;
int again;
// start loop
do
{
cout << "Enter the amount of gasoline in liters:";
cin >> liters;
cout << "Enter the number of miles traveled:";
cin >> miles;
// function definition
gallons = (0.264179 * liters);
miles_per_gallon = (miles/gallons);
// display output
cout << "The gas mileage of this travel is " << miles_per_gallon <<
cout << " miles per gallon "
<< endl;
cout << "Do you want to run this program again (yes=1, no=2)? ";
cin >> again;
// end loop
}while (again == 1);
system("PAUSE");
return EXIT_SUCCESS;}
May 4, 2013 at 11:22pm UTC
it looks like that is what i need, where do i put it in the code?
May 5, 2013 at 5:52am UTC
That page has an example.