Set precision???

Hi guys, I'm having problem getting set precision to work. Basically it is supposed to output $1.00-$10.00 but I am getting $1-$10. Any help would be gladly appreciated

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
	for(int i=1; i<11;i++)
	{
		cout << setw(5);
		cout << fixed << showpoint <<setprecision(2);
		cout << "$" << i << endl;
	}
	return 0;
}
Please try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
	for(int i=1; i<11;i++)
	{
		cout << setw(5);
		cout << fixed << showpoint <<setprecision(2);
		cout << "$" << setw(5) << (float)i << endl;
	}
	return 0;
}
Last edited on
thank you so much!!!! can you tell me what that is and why i need it? my professor never mentioned it.
Well, you declared int i but setprecision() works for float point numbers. So, in the line 10 (float)i is used for this. Only here, for this cout, int i will be...float i.
Last edited on
ohhhh okay i understand. thanks again for your help! :)
You're welcome! ;)
Topic archived. No new replies allowed.