How to make the Profit Output to round to two decimal places

Thnanks!
Last edited on
Hi,
> How to make the (profit) output to round to two decimal places
You simply need to set the output precision for std::cout before you output (profit)
1
2
cout.precision(2);
cout<<"\nProfit: "<< "$" << profit;
Last edited on
Does that help? :)
Inside of your printResults function, you could do the following:

1
2
3
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);


However, if you do this, then you should place the above three lines after

1
2
cout<<"\nISBN: "<<isbn;
cout<<"\nCopies: "<<copies;
Thanks for the replies. I tried doing the first suggestion

by adding the (cout.precision(2);)

cout<<"\nISBN: "<<isbn;
cout<<"\nCopies: "<<copies;
cout.precision(2);
cout<<"\nProfit: "<< "$" << profit;

And the results I got are:
Enter the Details of the books:
Enter book number: 0755798652
Enter price per copy: 34.98
Enter expected class enrollment: 35
Enter 'R' if required or 'S' is suggested: r
Enter 'N' if required or 'O' is suggested: O



The estimation for the next quarter is:
ISBN: 0755798652
Copies: 23
Profit: $1.6e+002
Press any key to continue . . .


it doesn't seem to work.


but when I tried the second suggestion:
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

It worked!!


But I would like to know why the first suggestion didn't work so I could know the different ways to achieve the same results.

Thanks for the help!
Topic archived. No new replies allowed.