When there are several cout statements, if the first cout statement has, say, << fixed << showpoint << setprecision(4), then all the subsequent cout statements *without* these settings will also have that effect. For example, in the following program,

cout << "sin(" << angle << ") = " << fixed << showpoint << setprecision(4) << sin(angle) << endl;
cout << angle;

suppose angle = 2. The second angle (last cout) will have four decimals displayed (2.0000):
Output:

sin(2) = 0.9093
2.0000

How to "deactivate" the format so that the second angle will display as the first one, i.e. just "2" ? Thanks in advance!

try removing fixed and showpoint

cout << "sin(" << angle << ") = "
       << setprecision(4) << sin(angle) << endl;
cout << angle;

try removing fixed and showpoint

Thank you--it works! But suppose in some circumstance we do need fixed and showpoint in the first cout statement, is there a way?

you can't deactivate precision control. the precision is initially 6 and is always used for floating point (and never for any other type). so you could either make angle an int you can also write

cout << "sin(" << angle << ") = " << fixed << showpoint << setprecision(4) << sin(angle) << endl ;
cout << noshowpoint << setprecision( 0 ) << angle ;

or

cout << "sin(" << angle << ") = " << fixed << showpoint << setprecision(4) << sin(angle) << endl ;
cout << resetiosflags( ios::fixed | ios::showpoint ) <<  angle ;

Thank you so much for the help! It works!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.