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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started