Classwork Help?

I need to write a program that gives this as the output:

3.1
3.14
3.142
3.1416
3.14159
3.141593


Please help, this is due in about 30 minutes.

EDIT: I forgot to mention that I need to use setprecision and setw.
Last edited on
So far I have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout<<setw(6)<<setprecision(2)<<3.1<<endl;
cout<<setw(5)<<setprecision(3)<<3.14<<endl;
cout<<setw(4)<<setprecision(4)<<3.142<<endl;
cout<<setw(3)<<setprecision(5)<<3.1416<<endl;
cout<<setw(2)<<setprecision(6)<<3.14159<<endl;
cout<<setprecision(7)<<3.141593<<endl;

return 0;

}


However, the setw stops working after the second line.
closed account (48T7M4Gy)
You must use setprecision etc in conjunction with std::fixed
Last edited on
Topic archived. No new replies allowed.