I just finished this and had a question.
I was asked to "create a void function called round() that rounds the value of its double argument to the nearest whole value. Have round() use a reference parameter and return the rounded result in this parameter."
Here's my code (which works fine now):
It works fine now but at first I kept getting an ambiguity error when I called the function. I knew this happens when you overload a function and feed it an ambiguous value. But I only had one function! I figured, then, that there must be another function in <cmath> with the same name... so I just changed the name of my function slightly and it compiled with no problems. After that I searched the <cmath> header but there doesn't seem to be a round() function in there at all!
// Rounding Program
using namespace std;
void rounD (double &val); // function prototype
cout << "Enter a value: ";
cin >> input;
cout << "\n\nRounded value is: " << input;
void rounD (double &val)
pintPart = &intPart;
double fracPart = modf(val, pintPart);
/* couts used in debugging - really helped!*/
cout << "Val: " << val << "\n";
cout << "fracPart: " << fracPart << "\n";
cout << "intPart: " << intPart << "\n";
if (fracPart >= 0.5) val = (intPart + 1);
else val = intPart;
So my question is: if my ambiguity error was caused by function overload, where did this other mysterious, invisible, trouble-making function come from? Or, if the error was not caused by function overload, what did cause it?
Guess that's a bit of a long way to ask a short question. Sorry for that. Any comments would be really appreciated, though.
Ps. I'm using Dev-C++ on Windows XP