1

I'm trying to get this program to read data from a .dat file but all I can get it to do is to run without actually displaying the date from the file. What am I missing here?

"
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <fstream>
#include <iterator>



using namespace std;

void calculation(double &, double &, double &, double & , double &, 
double &, double &,
              double &, double &, double &);



int main()
{


ifstream input_file;
string social_security, last_name, first_name;
double payrate, income_taxrate;
double rhours, ohours, thours;
double netpay, grosspay, overtimepayrate, regularpayrate;
int record_number = 1;
double taxes;

input_file.open ("employee.dat",ios::in);


while(!input_file.eof()&& record_number !=12)
{
input_file >> social_security
            >> last_name >> first_name
            >> thours >> payrate >> income_taxrate;

        regularpayrate = 0;
        overtimepayrate = 0;
        grosspay = 0;
        ohours = 0;

calculation(overtimepayrate, payrate, regularpayrate, grosspay,
            rhours, ohours, income_taxrate, netpay, thours, taxes);
cout << "Record #" << record_number
                         << "\n" << "Employee Social security #: " << 
social_security
                         << "\n" << "Last Name: " << last_name
                         << "\tFirst Name: " << first_name
                         << "\n" << "Hours Worked: "  << thours
                         << "\nPay Rate: $" << payrate;

          //Setting the overtime hours versus regular hours
        if(ohours > 0)
    {
        cout << "\n" << "Regular Pay "
             << 40.0 << " hours @ $"
             << payrate << ": $"
             << regularpayrate
             << "\n" << "Overtime Pay "
             << ohours << " hours @ $"
             << (payrate * 1.5) << " : $"
             << overtimepayrate;
    }
    else
    {
        cout << "\n" << "Regular Pay " << rhours << " hours @ "
             << payrate
             << " $"
             << regularpayrate;
    }
    cout << "\n" << "Gross Pay: $" << grosspay
         << "\n" << "Taxes @ " << (income_taxrate * 100) << "%: $" << 
taxes
         << "\n" << "Net Pay: $" << netpay
         << "\n\n\n";
    record_number++;

}


}


void calculation(double & overtimepayrate, double & payrate, double & 
regularpayrate
             , double & grosspay , double & rhours, double & ohours, 
double & income_taxrate,
              double & netpay, double & thours, double & taxes)
{



            if (thours> 40)
                {
                    rhours = 40;
                    ohours = thours - 40;
                }

            if (thours < 40)
                {
                    rhours = thours;
                }
//Calculations

                    overtimepayrate = ohours* (payrate*1.5);

                    regularpayrate = rhours * payrate;

                    grosspay = regularpayrate + overtimepayrate;

                    taxes = grosspay * income_taxrate;

                    netpay = grosspay - taxes;

}
void intro(){

    cout << "\n\tHello C++ user, I am a program that uses"
         << "\n\ta pointer function in order to access a"
         << "\n\tparticular data file.\n";


}
"

This is the data I want it to display when ran:

  • 123-45-6789 Kirk James 44.7 88.99 0.0175
  • 124-89-0007 Bond Jane 45.6 65.75 0.04
  • 405-77-8911 Puff Blossom 40 33.88 0.03
  • 405-10-9871 Puff Buttercup 41.2 45.66 0.047
  • 223-03-8761 Puff Bubbles 37.8 33.44 0.015
  • 980-11-2201 Joneski Kasey 23.1 10.77 0.033
  • 115-88-7619 Crooke I.M.A. 25.4 88.75 0.02
  • 777-00-1232 Smith Alias 43.5 22.3 0.034
  • 345-89-0022 DeMann Stan 56.7 29.45 0.065
  • 210-37-1192 Jones Jeane 48.9 20.33 0.025
  • 103-22-4321 Smith Alias 33.5 19.67 0.063
tjoak94
  • 11
  • 1
  • 2
    Please read [Why is iostream::eof inside a loop condition considered wrong?](https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong) – Some programmer dude Nov 29 '18 at 12:04

0 Answers0