How can I round off in C ++ without using a function?

Ky
3

I'm new to the computer science course and I'm pretty much on the ball:

Input and output are basically clear to me, but the following task requires more:

Create a Jupyter notebook that reads in a positive point number and a number of digits

The decimal point should then be based on the number of digits entered without using any completed rounding functions

be rounded off. The result should then be output.

Example:

Please the number to be rounded, with a point instead of a comma: (input field) 4.12345

How many digits should it be rounded down to? (Input field) 3

The number is rounded down to 3 digits: 4,123

Conditions:

Reading in a point number and a number of digits

Rounding down to the number of digits without using ready-made rounding functions

Output of the result

pl

You could turn the number into a string, from here the way should be clear.

You could multiply the number by 10 ^ digits, do an integral cast, and then divide again.

Possibly. Are there any other options?

Ch

You can break the input down into individual characters and then change them if you have to round them

Ky

How do I dismantle them? This is perhaps easier than doing the multiplication (as in the previous answer) several times if necessary