Richtige Formatierung
-
Das Programm gibt eine Tabelle mit Kreisradius, Umfang und Fläche aus.
Der Radius läuft von 1 bis 5 in 0.5er Schritten.#include <cmath> #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int main() { double r=0.5,u,A; cout << setprecision(3); cout << "Radius" <<" "<< "Umfang" <<" "<<"Flaeche"<< endl << endl; for (int i=1 ; i<=9 ; i++) { r = r+0.5; u = M_PI * 2*r; A = M_PI * r*r; cout << r <<" "<< u <<" "<< A << endl; } system("PAUSE"); return 0; }
Mein Problem ist, dass die Zahlen nicht schön geordnet untereinander stehen.
So sieht meine Ausgabe aus
1 6.28 3.14 1.5 9.42 7.07 2 12.6 12.6 . . .
-
Versuchs mal mit Tabulatorzeichen '\t' als Trennzeichen. Das ist simpel sollte in 90% der Fälle funktionieren.
cout << r <<'\t'<< u <<'\t'<< A << endl;
-
alternativ für etwas "fortgeschrittenere" Formatierungsprobleme die Stream-Manipulatoren - setw, setfill, setprecision