0

Here is my code, it is suppose to take the double num, round it, and return it using call by reference, but when i try to compile it gives me an ambiguity error at round(i); .

please help.

#include <iostream>
#include <cmath>
using namespace std;

void round(double &num);
int main()
{
    string line;
    
    double i = 100.7;
    cout << "Number i before rounding: " << i << "\n";
    round(i);
    cout << "Number i after rounding: " << i << "\n";
    
    double j = -3.3;
    cout << "Number j before rounding: " << j << "\n";
    round(j);
    cout << "Number j after rounding: " << j << "\n";
    
    getline(cin,line);
    cin.get();
    return 0;
}

void round(double &num)
{
     int value;
     int fraction;
     
     fraction = modf(num, &value);
     
     if(fraction < 0.5) num = value;
     else num = value + 1;
}
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by people123
0

Thanks, I was able to solve it by changing the function to void round(double *num) and the call to round(&i)

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.