set precision struggles.

I seem to be having some issues using set precision, fixed and a few other manipulators to fix my output with three decimal places as well as a decimal point showing up.
I have also tried moving the fixed, show point, and set precision in and out of the while function and have not come up with a fix.
Any help would be greatly appreciated.

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
32
33
34
35
36
37
38
39
  #include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;

int main(){
	// variable declarations
	double g = 32, t, d, counter = 1, a;
	// ask for input
	cout << "This Program displays the total distance fallen in second incriments" << endl;
	cout << "Please input a time in seconds: " << endl;
	cin >> t;
	cout << endl;
	// set up loop for invalids
	while (t < 1) {
		cout << "\nERROR! You did not enter a positive integer!" <<
			"input a postive interger: " << endl;
		cin >> t;
	}
	// set up display
	cout << setw(20) << "Time"
		<< setw(20) << "Interval Distance"
		<< setw(20) << "Total Distance" << endl;
	cout << setw(20) << "--------------------"
		<< setw(20) << "--------------------"
		<< setw(20) << "--------------------" << endl;
	cout << fixed;
	cout << showpoint;
	cout << dec;
	cout << setprecision(3);
	// loop for all numbers less than input.
	while (counter <= t) {
		cout << setw(20) << counter << setw(20) <<
			(a = .5 * g * pow(counter, 2) - (.5 * g * pow(counter - 1, 2))) <<
			setw(20) << (d = .5 * g * pow(counter, 2)) << endl;
		counter++;
	}
	return(0);
}
What exactly your problem is?
std::cout << std::fixed << std::setprecision(3) << 3.14159265358;
Should do the trick, but you are already using it.
Topic archived. No new replies allowed.