Help with reading from a file

I am a beginner, and I need to write a program that will read from a text file with four lines of
 
Saul Good#12.35 30 25 

Using different names and numbers of course. This compiles, however it only displays the heading when I run it. Any help greatly appreciated!
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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void instructions()
{

	cout << "This payroll program calculates an individual "
		 << "employee pay and\ncompany totals "
		 << "using data from a data file payroll.txt.\n" 
		 << "\n\nA payroll report showing payroll information "
		 << " is displayed.\n\n";
}


void reportTitle()
{

	cout << setprecision(2) << fixed << showpoint << left;


	cout << setw(20) << "Employee" << setw(10) << "Hourly" 
             << setw(10) << "Hours" << setw(10) << "Tax" << setw(10) 
             << "Gross" << setw(10) << "Net" << endl;

	cout << setw(20) << "Name" << setw(10) << "Rate" 
             << setw(10) << "Worked" << setw(10) << "Rate" << setw(10) 
             << "Amount" << setw(10) <<"Amount" << endl << endl;
}

void displayEmployeeInfo(string name, double hourly, double hours, double tax, double gross, double net)
{
    cout << setprecision(2) << fixed << showpoint << left;
    
    cout << setw(21) << name << setw(10) << hourly << setw(10) << hours << setw(10) << tax << setw(10) << gross << endl;
}

void totalAmounts(double total_gross, double total_net)
{
    cout << "Totals" << setprecision(2) << fixed << showpoint << right << setw(50) << total_gross << setw(10) << total_net << endl;
}

int main()

{
  ifstream fin;
    fin.open("payroll.txt");

    double total_gross = 0.0;
    double total_net = 0.0;

	instructions();


	reportTitle();


    string str;
    string name;
    double hourly;
    double hours;
    double tax;
    double gross;
    double net;
    double overtime;
    
    getline(fin, name, '#');
    
    

    while (!fin.eof());
    {

        fin >> hourly >> hours >> tax >> gross >> net;

        fin.ignore(100, '\n');

        if(hours <= 40)
        {
            gross = hours * hourly;
        }
        else if(hours > 40)
        {
            gross = 40 * hourly + overtime * hourly * 1.5;
        }
        net = gross - tax / 100 * gross;
        
        displayEmployeeInfo(name, hourly, hours, tax, gross, net);

        total_gross = total_gross + gross;
        total_net = total_net + net;
        
        getline(fin, name, '#');
    }
    
    totalAmounts(total_gross, total_net);
    fin.close();
}
With this code you are forever stuck in while loop because of while (!fin.eof());
The problem is with ';' at the end of while. So just remove ';' and u will be able to go inside the body of your while

But I think this line
fin >> hourly >> hours >> tax >> gross >> net;
should be changed to
fin >> hourly >> hours >> tax;

You are only reading 3 values from file and calculate the rest.
>> gross >> net; this will only try to read the next persons name as double digits and fin state will be set to fail and you will exit the while loop
Topic archived. No new replies allowed.