Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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.

image text in transcribed

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:

image text in transcribed

I just need help rounding correctly, please.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions