I was working on a praxctice program and wanted some numbers fixed dollar amounts to 2 decimal places while others to be displayed as plain old ints. I used this code, but noticed that now ALL numbers are set as fixed 2 place decimals. Is this how fixed and setprecisioun are supposed to work, or is it only supposed to effect the line of code they are associated with:
cout << endl << endl << endl; cout << "Loan Amount $" << fixed << setprecision(2) << loan << endl; cout << "Monthly Interest Rate: " << rate << "%" << endl; cout << "Number of Payments: " << payments << endl; cout << "Monthly Payment $" << setprecision(2) << payment << endl; cout << "Amount Paid Bacl $" << setprecision(2) << endl;
This code gives me something like:
%12.00 (I expected %12)
36.00 (once again expecting 36)
blah blah blah
you get the point, I don't think I'm understaning how these formatting commands work, the books don't seem to say anything on their scope.