Hello scubaa,
Along with what
jlb has mentioned this is a good place to start
http://www.cplusplus.com/reference/iomanip/
Look at "setw" and "setprecision".
I think what you are trying for is:
Seconds Distance
=====================
1 0.0000
2 16.0850
3 64.3400
4 144.7650
5 257.3600
6 402.1250
7 579.0600
8 788.1650
9 1029.4400
10 1302.8850
11 1608.5000
|
To start with put this before the for loop:
1 2 3 4
|
std::cout << std::fixed << std::showpoint << std::setprecision(4);
std::cout << "\nSeconds Distance\n";
std::cout << std::string(21, '=') << '\n';
|
Line 1 sets up to print 4 decimal places instead of the 6 numbers that is the default when not using "setprecision". The whole number part is counted in the 6. So 1.23456 or 10.3456 or 100.456 would print. Using the "setprecision" set to 4 you would get 1.1234 or 100.1234 which in the end will line up the decimal points.
For the for loop starting "i" at 1 works for what you want, but most things like arrays start at (0) zero and you should get use to working with that. Also the "<=" can cause a for loop to loop one more time that is need if you are not careful. You for loop would be better as
for (int i = 0; i < 10; i++)
and even better is
for (int i = 0; i < MAXLOOPS; i++)
where "MAXLOOPS" is defined as
constexpr int MAXLOOPS{ 10 };
and I put this at the top of "main". Sometimes you may want to define this as a global variable to use anywhere in the file.
Inside the for loop you would write
cout << i + 1 <<...
to compensate for starting at (0) zero.
The last point is in the for loop instead of setting "d" equal to the return value of the function and then using "d" in the "cout" statement you can put the function call in the "cout" and it will print the returned value after first being called.
That should be enough to get you started. Adjust your code and post it in a new message. Then if you are having problems they can be addressed then.
Andy