Hello! I have a floating point number from which I have to output only the decimals. The problem is that my teacher wants us to output 20 exact decimals from that number, separated by a space. I thought about using setprecision(20), but I don't know how to use it in other way than with std::cout .
1 2 3 4 5 6 7
//I actually intend to attribute these decimals to a variable(if it's
I am only sure of two ways to set the precision and that is std::cout << std::setprecision(20) or std::cout.precision(20). Since "setprecision" is a stream manipulator it will be be the easiest way to show 20 decimal places.
An alternative would be to put the number into a string and pad the right side of the number with zeros before you print it to the screen.
This will only output one number. Even if you move the closing brace to the end it won't work. Why are you adding L to Lt each time through the loop? Why are you recomputing L each time through the loop? Why are you printing the fractional part when you want to print individual digits (which suggests printing the integer part)?
My advice is to throw away this code and try to write this function again from scratch.
Mr jonathan is a plumber. n represents the number of streets he works on. Each street has one pipe that needs to be repaired. Mr jonathan wrote two numbers.Their ratio represents the lenght of the pipe.
We need to find the total lenght of all pipes (Lt) and output only the decimals of it.
7 , 5 the sizes of the pipe
This means 7/5=1,4, so we will have 4 0 0 0 0 0 0 ...(20 times) as output.(Notice that the decimals are separated by a space)
Pretty stupid assignment imo...