How to create file using calculated data

Hello,

I'm trying to figure out how to create a txt that will display information such:
-------------
LAST, FIRST
Gross:
Tax:
Tax:
Tax:

Net:
-------------
My code works and calculates the taxes correctly, but I need to then store that information on a file (similarly to a pay stub). Thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;

int main()
{
	//Vbl Dec
	double gross = double();
	string fname = string();
	string lname = string();
	double fedinctax = double();
	double statetax = double();
	double sstax = double();
	double meditax = double();
	double penplan = double();
	int healthin = 75;
	double netpay = double();

	//Vbl Manip
	cout << fixed << setprecision(2);

	//In
	cout << "Enter your first name: " << endl;
	cin >> fname;
	cout << "Enter your last name: " << endl;
	cin >> lname;
	cout << "Enter pay period gross amount: " << endl;
	cin >> gross;
	cout << "============================" << endl;

	//Calc
	fedinctax = gross * .15;
	statetax = gross * .035;
	sstax = gross * .0575;
	meditax = gross * .0275;
	penplan = gross * .05;
	netpay = gross - fedinctax - statetax - sstax - meditax - penplan;

	//Out

	ofstream out;
	out.open("paycheck.txt");
	

		cout << setfill('.') << left << setw(25) << "Gross amount:"
			<< setfill(' ') << right << "$" << setw(1) << gross << endl;
		cout << setfill('.') << left << setw(25) << "Federal income tax:"
			<< setfill(' ') << right << "$" << setw(1) << fedinctax << endl;
		cout << setfill('.') << left << setw(25) << "State tax:"
			<< setfill(' ') << right << "$" << setw(1) << statetax << endl;
		cout << setfill('.') << left << setw(25) << "Social security tax:"
			<< setfill(' ') << right << "$" << setw(1) << sstax << endl;
		cout << setfill('.') << left << setw(25) << "Medicare/Medicaid tax:"
			<< setfill(' ') << right << "$" << setw(1) << meditax << endl;
		cout << setfill('.') << left << setw(25) << "Pension plan:"
			<< setfill(' ') << right << "$" << setw(1) << penplan << endl;
		cout << setfill('.') << left << setw(25) << "Health insurance:"
			<< setfill(' ') << right << "$" << setw(1) << healthin << "\n" << endl;
		cout << setfill('.') << left << setw(25) << "Net pay(amount payed):"
			<< setfill(' ') << right << "$" << setw(1) << netpay << endl;
		cout << "============================" << endl;
	

	system("pause");
}
Topic archived. No new replies allowed.