Making a table.

Hi guys,

I have to set up a table like this. Any advice on how I should start? :O

http://oi43.tinypic.com/2em0l8g.jpg

Look up the setw() function
This is what I have at the moment:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//Example: setprecision, fixed, showpoint

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
	double x,y,z;
	float A = 9 ;
	string  Temp = "Hello";


	x = 15.673;						
	y = 235.736;						
	z = 9525.9864765;

	cout <<"\n\t\tUsing fixed, showpoint(to show the trailing 0's), \n\t\t\tshowpos (to show + sign): \n" ;
	cout <<"\t\t\t, setw(20), setprecision(2),and right\n " <<endl ;
	cout <<showpoint<< showpos << right ; 	

	cout <<"x"<< setw(15) <<"y"<< setw(15) <<"z"<< setw(15) <<"A"<< setw(15) <<"Temp"<< endl;					
	cout << x << setw(15) << y << setw(15) << z << setw(15) << A << setw(15) << Temp << endl ; 

	cout << "press enter to continue: " ;
	cin.get();

	return 0;
}


I still don't know if I did it right or not, since we were supposed to modify a code given from the professor. Originally, it is setw(20), but I changed it to 15. Not sure if that was allowed or not.

Now, I don't know how to show the correct number of digits for those values. I tried using setprecision, but it didn't work for all of them. Showpoint gave me an error, I guess I am not using them correctly.

Anyone? :(
Topic archived. No new replies allowed.