I am trying to make the code below display the result with decimals. I tried using setprecision, but I am not too sure where to put it. I placed it in cout section where the answer is but it still doesn't come out correctly. Any feedback would be great.
Thanks in advance!
#include <iostream>
using namespace std;
//*Delcare function prototype*
int ConvertToCentimeters (double, double );
//declare exception class*
class NegativeNumber
{};
int main ( )
{
double inch = 0;
double cent = 0;
double answer;
char ContinuationFlag = 'Y';
while (toupper(ContinuationFlag) == 'Y')
{
cout << "Enter Inches for conversion : " << endl;
cin >> inch;
try
{
answer = ConvertToCentimeters ( inch, cent);
cout << "The conversion to centimeters is: " << answer << endl;
}
catch ( NegativeNumber )
{
cout << "Inches cannot be negative!" << endl;
}
cout << "Do you wish to enter any more numbers?" << endl;
cout << "Enter 'Y' or 'N'" << endl;
cin >> ContinuationFlag;
}
return 0;
}
int ConvertToCentimeters(double InputInch, double InputCent )
{
if ( InputInch < 0 )
{
throw NegativeNumber();
}
return (InputInch * 2.54 );
}