#include <iostream> using namespace std; int main() { cout << -0.152454345 << " " << -0.7545 << endl; cout << 0.15243 << " " << 0.9154878774 << endl; } Outputs:
-0.152454 -0.7545 0.15243 0.915488 I want the output to look like this:
-0.152454 -0.754500 0.152430 0.915488 My solution:
#include <iostream> #include <iomanip> using namespace std; int main() { cout << fixed << setprecision(6) << setw(9) << setfill(' ') << -0.152454345 << " "; cout << fixed << setprecision(6) << setw(9) << setfill(' ') << -0.7545 << endl; cout << fixed << setprecision(6) << setw(9) << setfill(' ') << 0.15243 << " "; cout << fixed << setprecision(6) << setw(9) << setfill(' ') << 0.9154878774 << endl; } The output is good, but the code is terrible. What can be done? Here is my code https://ideone.com/6MKd31