Outputfile problem

My output file needs to be accurate to 2 decimal places but it displays three. Any advice?


#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cmath>

using namespace std;

int main()
{
string name = string();
double gross = double();
double fedtax = double();
double statetax = double();
double sstax = double();
double medtax = double();
double pension = double();
double health = double();
double net = double();
double fedt = double();
double statet = double();
double sst = double();
double medt = double();
double pent = double();

fedt = (0.15);
statet = (0.035);
sst = (0.0575);
medt = (0.0275);
pent = (0.05);

ifstream in;
ofstream out;

out.open("G:\\out.txt");






cout << "Enter first and last name with a space in between:";
getline (cin,name);
cout << "Enter gross pay:";
cin >> gross;

fedtax = (gross * fedt);
statetax = (gross * statet);
sstax = (gross * sst);
medtax = (gross * medt);
pension = (gross * pent);
health = (75.00);
net = gross - (fedtax + statetax + sstax + medtax + pension + health);


//cout << showpoint;
cout << fixed << setprecision(2);
//out << showpoint;
out << fixed << setprecision(2);

cout << name << endl;
cout << "Gross Amount:" << setw(20) << setfill('.') << "$" << gross << endl;

cout << "Federal Tax:" << setw(21) << setfill('.') << "$" << fedtax << endl;

cout << "State Tax:" << setw(23) << setfill('.') << "$" << statetax << endl;

cout << "Social Security Tax:" << setw(13) << setfill('.') << "$" << sstax << endl;

cout << "Medicare/Medicaid Tax:" << setw(11) << setfill('.') << "$" << medtax << endl;

cout << "Pension Plan:" << setw(20) << setfill('.') << "$" << pension << endl;

cout << "Health Insurance:" << setw(16) << setfill('.') << "$" << health << endl;

cout << "Net Pay:" << setw(25) << setfill('.') << "$" << net << endl;




out << name << endl;
out << "Gross Amount:" << setw(20) << setfill('.') << "$" << gross << endl;

out << "Federal Tax:" << setw(21) << setfill('.')<< "$" << fedtax << endl;

out << "State Tax:" << setw(23) << setfill('.') << "$" << statetax << endl;

out << "Social Security Tax:" << setw(13) << setfill('.') << "$" << sstax << endl;

out << "Medicare/Medicaid Tax:" << setw(11) << setfill('.') << "$"<< medtax << endl;

out << "Pension Plan:" << setw(20) << setfill('.') << "$" << pension << endl;

out << "Health Insurance:" << setw(16) << setfill('.') << "$" << health << endl;

out << "Net Pay:" << setw(25) << setfill('.') << "$" << net << endl;


return 0;
}
do i set out precision just about the out section?
Topic archived. No new replies allowed.