199,228 views
43 votes
43 votes
Write a cout statement so the variable sales is displayed with a precision of three decimal places, with the decimal point always displayed.

User Will Alexander
by
3.2k points

1 Answer

11 votes
11 votes

Answer:

The statement is as follows:

cout <<fixed<< setprecision(3) <<sales;

Step-by-step explanation:

Here, I assume that the variable has already been declared.

The syntax to use is:

cout<<fixed<<setprecision(n)<<variable-name;

In this case:


n = 3 --- i.e. to 3 decimal places

And the variable name is: sales

So, when implemented, the instruction is:

cout <<fixed<< setprecision(3) <<sales;

User Chughts
by
2.5k points