0
accuracy of four decimal spaces
I've written this code #include <iostream> #include <cmath> using namespace std; int main() { float disGh, disP, dGholi, dPoli; double thGholi, thPoli; cin >> dGholi >> thGholi; cin >> dPoli >> thPoli; disGh = dGholi / (2*(1-pow(0.5000,thGholi))); disP = dPoli / (2*(1-pow(0.5000,thPoli))); if (disGh > disP) cout << "GHOLI WINS" << endl << disGh; else if (disGh < disP) cout << "PPOLI WINS" << endl << disP; else cout << "DRAW" << endl << disGh; } and it does what I want just fine, the problem is that for example if I put "14 3 15 2" in it, it gives POLI WINS 10 but I want it to say 10.0000 with 4 decimal spaces I was wondering if there was a function that could do it
1 Odpowiedź
+ 4
#include <iomanip>
cout << setprecision(6) << showpoint;
Put the line (above)... anywhere before you want it to take effect.
..please note.. they are modal .i.e. they stay in effect until you change them to something else.