Question: Rounding in C++ Hello, I need to create a function that will round off values that I have already read in from a file. This
Rounding in C++
Hello, I need to create a function that will round off values that I have already read in from a file.
This is what the function should do:
round_off(value, places): Receives a value (double precision real number) and a number indicating a quantity of decimal places (whole number) and returns the value rounded to the specified number of places.
You can think of each row as coordinates a, b, and c.
The values are
1.03, 1.19
6.0, 5.96
3.04, 6.5
These values must become the following (in same order as above)
1.0, 1.2
6.0, 6.0
3.0, 6.5
It's measuring the distance from a to b, from b to c, and then from a to c in case you get confused.

This is my function but it does not round off the way it must be.
double round_off(double value, int places) { value = floor(value * pow(10.0, places) + 0.5 / pow(10.0, places)); return value;
}
and this is what I get:

I just need help rounding correctly, please.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
