My program involves getting double input, performing some calculations, and then displaying the double results along with the original input. I have the whole thing set to cout << fixed << showpoint; and I am using setprecision(2) to make the results show to 2 decimal points. My problem is that I want the displayed output of the initial input to look exactly like the input, e.g. if the input was 4 I want it to output "4" not "4.00000...", or if it was 3.456 output "3.456". How do I do this?
How else could we do it?
The same number can be specified in a variety of formats.
1 2 3
double a = +1.2345e+2, b = 123.45, c = +123.45, d = 12345e-2, e = 000.012345e4 ;
// this will display 123.45 five times
std::cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << '\n' ;
> I don't think we've covered strings in class yet.
That shouldn't prevent you from using it.
Though it is not ideal, we could also use a c-style string.