0

Please help, I can't get more than 5 decimal places in my answers and I don't know how to tweak the code to allow for this. Any help would be greatly appreciated. DB

#include <iostream>


using namespace std;

int main()
{
system("title You can Convert Miles to Kilometers or Convert Gallons to Liters");
system("color 17");

long double mile;
long double gallon;
char choice;
for (;;){
do {
cout<<"Welcome to my special conversion program.\n";
cout<<"\n";
cout<<"Please choose one from the following menu and press enter.\n";
cout<<"\n";
cout<<"************************************************\n";
cout<<"Exit Program\t\t\t Enter q\n";
cout<<"Convert Miles to Kilometers\t Enter 1\n";
cout<<"Convert Gallons to Liters\t Enter 2\n";
cout<<"************************************************\n";
cin>>choice;
} while ( choice < '1' || choice > '2' && choice != 'q');
if (choice == 'q') break;
switch (choice) {
case '1':
cout<<"Please enter how many MILES you want to convert to KILOMETERS\n";
cin>>mile;
cout<<"\n";
cout<<"Your total kilometers are\t"<< mile * 1.609344;
cout<<"\n";
cout<<"\n";
break;
case '2':
cout<<"Please enter how many GALLONS you want to convert to LITERS\n";
cin>>gallon;
cout<<"\n";
cout<<"Your total liters are\t"<< gallon * 3.78541178;
cout<<"\n";
cout<<"\n";
break;

}

}
return 0;


}

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by barnes138
0

try using...

#include <iomanip>

cout.setf(ios::fixed, ios::floatfield);
cout.precision(8); // sets number of decimal places

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.