Well I need some answers regarding alignment. I have read a bit about it but I can't seem to make it become like I want.
I have put ta sample below of the output I got and the output I expect to get. You will see that the numbers in the "Square" column are not aligned well, they get our in the left :(
Anyone has a good tutorial on these alignment thing. I want to be able to master this but it doesn't seem right. If the numbers are large enough, I notice that the column get "disrupted". I appreciate all your help.
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
int main()
{
int x;
ofstream f("squares.txt");
cout << "Enter the numbers you want followed by a 0: ";
cin >> x;
cout << "Number" << setw(90) << right << "Square" << endl << endl;
f << "Number" << setw(90) << right << "Square" << endl << endl;
while (x!=0){
cout << x << setw(90) << right << (x*x) << endl;
f << x << setw(90) << right << (x*x) << endl;
cin >> x;
}
cout << "All data written to squares.txt" << endl << endl;
f.close();
return 0;
}
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
int main()
{
int x;
ofstream f("squares.txt");
cout << "Enter the numbers you want followed by a 0: ";
cin >> x;
cout << left << setw(15) << "Number";
cout << left << setw(15) << "Square" << endl;
f << left << setw(15) << "Number";
f << left << setw(15) << "Square" << endl;
while (x!=0){
cout << left << setw(15) << x;
cout << left << setw(15) << x*x << endl;
f << left << setw(15) << x;
f << left << setw(15) << x*x << endl;
cin >> x;
}
cout << "All data written to squares.txt" << endl << endl;
f.close();
return 0;
}