0

So I'm new to C++ language and I'm not sure what is wrong with this code right. btw, this is not my code, it is from a book called Absolute C++ for Savitch.

I get following error messages: overloaded function differs only by return type and error in function definition or declaration

Here is the code:

#include <iostream>
#include <cmath>

using namespace std;

int round(double number);
// Assumes number >= 0.
// Returns number rounded to the nearest integer.

int main()
{
    double doubleValue;
    char ans;

    do
    {
        cout << "Enter a double value: ";
        cin >> doubleValue;
        cout << "Rounded that number is " << round(doubleValue) << endl;
        cout << "Again? (y/n): ";
        cin >> ans;
    } while (ans == 'y' || ans == 'Y');
    cout << "End of testing.\n";

    return 0;
}

// Uses cmath:
int round(double number) 
{ 
    return static_cast<int>(floor(number + 0.5)); 
}
dboy
  • 1,004
  • 2
  • 16
  • 24
  • 4
    See [this](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) Your `round` is conflicting with `std::round`. – cigien May 01 '20 at 22:41
  • 1
    Also, we have [a list of good C++ books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) if you want to take a look. – Yksisarvinen May 01 '20 at 22:53
  • Rename your `round` to `notstd_round`. – Eljay May 01 '20 at 23:32

0 Answers0