66 819
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #25078 in C++ for Dave

Question #25078
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>
Expert's answer
#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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions