0

format editing using setw i want to ask how to line up the output of area,focus and circum on one column from right to left

#include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; int main() { double a, b, area, circumference, focus; cout <<" This program calculates the focus, area and circumference of a eclipse "<<endl; cout <<" Enter the semi-major axis value: "; cin>> a; cout <<" Enter the semi-minor axis value: "; cin>> b; cout<<"\n"; cout <<" Thank you "; cout<<"\n"; // formulas for focus, area and circumference of the eclipse. focus = sqrt(pow(a,2)-pow(b,2)); area = M_PI*a*b; circumference = (M_PI*3*(a+b)) - (M_PI*sqrt((10*a*b)+3*pow(a,2)+3*pow(b,2))); cout << " The focus of the ellipse is: " <<setw(15)<<setprecision(2)<<fixed<<focus<<endl; cout << " The ellipse area is: " <<setw(15)<<setprecision(2)<<fixed<<area<<endl; cout << " The ellipse circumference is: " <<setw(15)<<setprecision(2)<<fixed<<circumference<<endl; return 0; }

13th Oct 2017, 7:56 PM
Anh Lam
Anh Lam - avatar
1 Respuesta