Using multiple functions.

Hi guys,

My assignment is to use the following input data and print out a report of their salary.

Miss Informed
12
5432 32560.0
Sweet Tooth
5432 9500
Bad Data
1255
-
4500.0
John Smith
1225 3500.0
Nancy Brown
1555 154500.00

I am not sure how to explain this, but this is the full question: The user will be asked for an input and output file name . The input file contains name, ID (4 digit integer), and the annual income for a list of people. In response, our program will verify the ID number and the year's earnings are numeric and if values are verified calculate the amount of income tax which should be paid and print a report similar to the sample below. Tax is calculated according to the table below. If data is Incorrect print an error message and continue processing the next set of data. Make sure to verify the file exists and has data in it, otherwise print an error message.

This is the tax table.

http://i41.tinypic.com/4nmlg.png

To be honest, I have no clue to how to get started with this one, nor do I have any idea how to use these sorts of functions or output/input text files. Please be patient and guide me through this assignment. Thank you in advance. :)

This is all I have at the moment, of course it doesn't work. :(

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
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std ;

int main()
{
	float income, tax, gross, netincome;  

	cout <<"\nEnter the name and location of the input file: ";
    string file_input;
    getline(cin, file_input);
    ifstream fin( file_input.c_str() );
    
    if(fin.fail())
    {
        cout << "Bad file name or location.\n";
        exit(0);
    }
    
    cout << "Enter the name and location of the output file: ";
    string file_output ;
    getline(cin, file_output);
    ofstream fout( file_output.c_str() );

	if (income < 3500)
		tax = 0;
	if (income > 3500 && income < 8000)
		tax = ( (income - 3500) * 0.06);
	if (income > 8000 && income < 20000)
		tax = ( (income - 8000) * 0.11) + 270;
	if (income > 20000 && income < 34000)
		tax = ( (income - 20000) * 0.17) + 1590;
	if (income > 34000 && income < 54000)
		tax = ( (income - 34000) * 0.24) + 3970;
	if (income > 54000)
		tax = ( (income - 52000) * 0.32) + 8770;
	netincome = gross - tax;

	cout << "\n\n";

	cout << right << "Name";
	cout << setw(19) << "ID";
	cout << setw(18) << "Gross Income";
	cout << setw(17) << "Taxes";
	cout << setw(17) << "Net Income";
	cout << "\n\n";

	cout <<  fixed << setprecision(2) << showpoint << setw(10) << "$" << income;
	cout << setw(11) << "$" << tax;
	cout << setw(8) << "$" << netincome;

	cout << "\n\n";

	return 0;
}


What should I do next? I copied the data into a text file already.
Any hints, tips, or advices, guys? I'm in a bind here.
This thread has a similar problem :

http://www.cplusplus.com/forum/beginner/115508/

Get some ideas from there and if ever you have problems, just post it

Hope this helps ...
Last edited on
Similar problem? His post has nothing. I have no idea what exactly was he dealing with, except that he was trying to do some void and function like me.
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <iomanip>
using namespace std;
 
int main()
{
ifstream fin;
ofstream fout;
double income, tax, netincome; 
int id; 
string file_output;
string file_input;
string name, lastName; 

void result (string name, string lastName, int id, double income, double tax, double netincome);
{
cout << name << " " << lastName;
cout << setw(13) << id;
cout << setw(14) << income;
cout << setw(19) << tax;
cout << setw(14) << netincome << "\n\n";
}
 
cout << "\nEnter the name and location of the input file: ";
 
getline(cin, file_input);
fin.open(file_input.c_str()); 
 
if (fin.fail())
{
cout << "Bad file name or location.\n";
exit(0);
}
 
cout << "Enter the name and location of the output file: ";
getline(cin, file_output);
fout.open(file_output.c_str()); 

cout << "\n\n";
cout << right << "Name";
cout << setw(19) << "ID";
cout << setw(24) << "Gross Income";
cout << setw(13) << "Taxes";
cout << setw(16) << "Net Income";
cout << "\n\n";

while (fin >> name >> lastName >> id >> income)
{
if (income <= 3500) 
{
tax = 0;
netincome = income;
cout << name << " " << lastName;
cout << setw(16) << id;
cout << setw(16) << income;
cout << setw(16) << tax;
cout << setw(14) << netincome << "\n\n";

}
else if (income > 3500 && income <= 8000) 
{
tax = ((income - 3500) * 0.06);
netincome = income - tax; 
cout << name << " " << lastName;
cout << setw(13) << id;
cout << setw(14) << income;
cout << setw(19) << tax;
cout << setw(14) << netincome << "\n\n";
 
}
else if (income > 8000 && income <= 20000) 
{
tax = ((income - 8000) * 0.11) + 270;
netincome = income - tax;
cout << name << " " << lastName;
cout << setw(13) << id;
cout << setw(14) << income;
cout << setw(19) << tax;
cout << setw(14) << netincome << "\n\n";
 
}
else if (income > 20000 && income <= 34000) 
{
tax = ((income - 20000) * 0.17) + 1590;
netincome = income - tax;

cout << name << " " << lastName;
cout << setw(13) << id;
cout << setw(14) << income;
cout << setw(19) << tax;
cout << setw(14) << netincome << "\n\n";
 
}
else if (income > 34000 && income >= 54000)
{
tax = ((income - 34000) * 0.24) + 3970;
netincome = income - tax;

cout << name << " " << lastName;
cout << setw(13) << id;
cout << setw(14) << income;
cout << setw(19) << tax;
cout << setw(14) << netincome << "\n\n";
 
}
else if (income > 54000){
tax = ((income - 52000) * 0.32) + 8770;
netincome = income - tax;
cout << name << " " << lastName;
cout << setw(13) << id;
cout << setw(14) << income;
cout << setw(19) << tax;
cout << setw(14) << netincome << "\n\n";
}
else
cout << "ivalid income";
}

fin.close();
fout.close();
cout << "\n\n";

return 0;
}


This is what I have so far. Where else do I go from here? Help me guys, it's due tomorrow and I barely have a clue what to do next. :O
Topic archived. No new replies allowed.