Answer to Question #25078 in C++ for Dave
I am trying to make a program that will find pi to an imputed specificity.
excerpt that's not working:
cout << "\n OK, so how many values of Pi do you want?\n";
cin >> valuecount;
cout << fixed << setprecision(valuecount) << 22/7 << endl;
example:
If i input 4, i get 1 digit, or "3", instead of "3.141"
everything is already defined at the top:
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <iomanip>
1
2013-02-26T11:16:06-0500
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <iomanip>
using namespace std;
int main()
{
cout<<"How many values of PI do you want ?\n";
int valuesCount;
cin>>valuesCount;
//the problem was that you divide integer values but not double (use 22.0 instead of 22)
cout<<setprecision(valuesCount)<<22.0/7.0;
cin.get(); //suspend console
cin.get(); //suspend console
return 0;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++
Comments
Leave a comment