Programming Rounding Numbers
Hello, Everyone:
I am having trouble with programming a program which rounds numbers to the hundreths place. I can show you my job but it does not compile.
Code:
#include<iostream>
using namespace std;
#include<cmath>
double roundtohundreths (double);
int main()
{
int t = 'Y';
double x;
while( t != 'N' && t != 'n' )
{
if ( t == 'Y' || t == 'y' )
{
cout << "Enter number: ";
cin >> "%lf", &x;
while( getchar() != '\n' );
cout << "Original value is: " << " x " << endl;
cout << "Rounded number is: " << " roundtohundreths( x ) " << endl;
}
cout << "Type Y for entering a number or N to end ): " << endl;
t = getchar();
}
return 0;
}
double roundtohundreths (double a)
{
double roundto = floor( a * 100 + .5 ) / 100;
return roundto;
}
The following error is:
<pegasus> g++ numerical.cpp
numerical.cpp: In function `int main()':
numerical.cpp:17: implicit declaration of function `int getchar(...)'
<pegasus>
Please help me figure out my mistake. Thank you very much in advance for helping me figure out my mistake.
Thank you,
Mike