CPPForSchool.com: Variable, Operator & Expression Set 2: Assignment 10
10.
What is the output of following program?
float net = 5689.2356;
cout.precision(2);
cout.setf(ios::fixed | ios::showpoint);
cout << net << endl;
After quickly researching what the precision function accomplishes, I was able to interpret the code. From what I understand, precision sets how many number spaces behind the decimal will output. For example, if the float in question is 1234.123456789 and the precision has been set to 2 spaces, then the number would display as "1234.12". Of course, the best way to test this answer is to simply compile the code. Once again, the iomanip library will need to be included in order to compile the code successfully.
It appears that my answer was correct! However, I went ahead and tested my answer via code. Below are the results.
Success!
float net = 5689.2356;
cout.precision(2);
cout.setf(ios::fixed | ios::showpoint);
cout << net << endl;
After quickly researching what the precision function accomplishes, I was able to interpret the code. From what I understand, precision sets how many number spaces behind the decimal will output. For example, if the float in question is 1234.123456789 and the precision has been set to 2 spaces, then the number would display as "1234.12". Of course, the best way to test this answer is to simply compile the code. Once again, the iomanip library will need to be included in order to compile the code successfully.
It appears that my answer was correct! However, I went ahead and tested my answer via code. Below are the results.
Success!
Comments
Post a Comment