0

Please how do I write a c++ program that allows my user input double precision floating point values

12th Jan 2020, 1:15 PM
Nehemiah oseremen
Nehemiah oseremen - avatar
8 Réponses
+ 1
Nehemiah oseremen , you should use setpricision as below: #include <iostream> #include <iomanip> using namespace std; int main() { double d; cin >> d; cout << fixed << setprecision(2); cout << d << endl; return 0; } your cin statement ask you to provide input value when your code execution reaches that line. on solo learn app as of now, all the input by user should be provided when you start the execution by hitting run button.
12th Jan 2020, 3:01 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Double precision is accuracy upto two decimals. I presume that question is asked for 2 decimal accuracy. Double and float does not provide decimal accuracy and setpricision is the one which helps
12th Jan 2020, 3:13 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
12th Jan 2020, 3:22 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
double d; cin >> d; cout << d;
12th Jan 2020, 1:17 PM
HonFu
HonFu - avatar
0
So where do I input this in my program?
12th Jan 2020, 1:22 PM
Nehemiah oseremen
Nehemiah oseremen - avatar
0
What does setprecision have to do with the question?
12th Jan 2020, 3:05 PM
HonFu
HonFu - avatar
0
Not really......I just need all the values to be double precision I'm using them to calculate the sum, average, and minimum and maximum of the values inputted.
12th Jan 2020, 3:15 PM
Nehemiah oseremen
Nehemiah oseremen - avatar
0
Ketan Lalcheta, your terminology is confused. 'Double precision' is not really about two decimal places. Read up here: https://en.m.wikipedia.org/wiki/Double-precision_floating-point_format
12th Jan 2020, 3:24 PM
HonFu
HonFu - avatar