Using setw w/showpoint and setprecison won't indent?

Tried to ask my prof a question today about it but she didn't explain why. With line 21, when I run it as is it displays 7.000 as desired, but not spaced 5 spaces. Tried searching my problem and consulting the textbook but nothing came up. It feels kind of silly as if I'm missing a minor thing.

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
  //This program is to practice formatting outputs with stream manipulators
#include <iostream>
#include <iomanip>
using namespace std;

int main(int argc, char** argv) 
{
	
	//Values are declared here
	double value1 = 34.789;
	double value2 = 7.0;
	double value3 = 5.789e+12;
	double value4 = 67;
	
	//Display the number 34.789 in a field of nine spaces with two
	//decimal places of precision
	cout << setw(9) << setprecision(5) << value1 << endl;
	
	//Display the number 7.0 in a field of five spaces with three decimal
	//places of precision, with decimal point/trailing zeroes displayed
	cout << setw(5) << setprecision(4) << showpoint << value2 << endl;
	
	//Display the number 5.789e+12 in fixed point notation
	cout << fixed << value3 << endl;
	
	//Display the number 67 left justified in a field of seven spaces
	cout << left << setw(7) << value4 << endl;
	
	return 0;
}
The size of 7.000 is 5 in ascii.
The text hugs the right side of where setw is, so 5 for setw gives no space.

Since 34.789 has the size of 6 and setw is 9, it gives 3 spaces.
   34.789
Last edited on
Topic archived. No new replies allowed.