|
-
March 1st, 2010, 04:26 PM
#1
outFILE setprecision and right wont work
Hi guys, I can't seem to use setprecision, right, setw, or fixed on my outFILE lines. nothing happens. I need to get all the decimals to line up and the numbers are on the right side.
this is my code so far
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main ()
{
ofstream outputFile;
double sales , total , year , statetax, countytax;
char month[10];
outputFile.open("sales.txt");
cout << "Please enter the month for this report:";
cin >> month;
cout << "Please enter the year for this report:";
cin >> year;
cout << "Please enter the total income for this month:";
cin >> total;
sales = total / 1.06;
cout << "Sales Tax Report saved to file: SalesTaxData.txt" << endl;
outputFile << "Month: " << month << endl;
outputFile << "-------------" << endl;
outputFile << "Total Collected: " << total << endl;
outputFile << "Sales : " << sales << endl;
countytax = sales * .02;
statetax = sales * .04;
outputFile << "County Sales Tax: $" << countytax << endl;
outputFile << "State Sales Tax: $" << statetax << endl;
outputFile << "Total Sales Tax: $" << countytax + statetax << endl;
cout << setprecision(2) << right << fixed << endl;
outputFile.close();
return 0;
}
-
March 2nd, 2010, 02:37 AM
#2
Re: outFILE setprecision and right wont work
You should use these manipulators before you reference the variables. For example,
double x = 1.23456
cout << setprecision (5) << x << endl;
-
March 2nd, 2010, 04:34 AM
#3
Re: outFILE setprecision and right wont work
 Originally Posted by Sabensohn70
Hi guys, I can't seem to use setprecision, right, setw
I don't see you using setw.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Please read Information on posting before posting, especially the info on using [code] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|