Assignment was to take information about sales made, hours worked and number of dependents from a file, calculate the gross pay expected on one of two plans
Plan A 10% commission on sales, and 9.50 an hour with 1.5x overtime after 40 hrs
Plan B 30% commission

then we had to calculate all tax deductions for the higher paying plan and output these to both the screen and an output file.
I keep getting an unhandled exception error at my gross pay pointer planA inside the PickaPlan function.
Any suggestions or comments are greatly appreciated.

Here is the input file

1200.00 45 1
1200.00 40 3
1200.00 35 4
1875.50 35 3
1875.50 40 5
1875.50 45 2
2250.75 48 4
2250.75 40 3
2250.75 35 2

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

const double COMMISSION_RATEA = .10;  
const double COMMISSION_RATEB = .3;
const double SOC_SEC_RATE = .06;
const double PAY_RATE = 9.5;
const double FED_TAX = .125;
const double STATE_TAX = .08;



char PickaPlan(float, int, float *, float *);

void OutputandRecord(float, int, int, char, ofstream&, float *, float *);


int main()
{
  float inSales;
  int inHours, inDep;
  char plan;
  
  float* planA;
  float* planB;

  //declare fstreams and open files
  ifstream fin;
  fin.open("salary3.in");
  
  ofstream fout;
  fout.open("salary3.out");

  //output header
  cout << "  Gross   Plan    Social     State      Federal     Health     Net  " << endl;
  cout << "   Pay           Security  Income Tax  Income Tax  Insurance   Pay  " << endl;
  cout << " ------- ------  --------  ----------  ----------  ---------  ----- " << endl;

  fout << "  Gross   Plan    Social     State      Federal     Health     Net  " << endl;
  fout << "   Pay           Security  Income Tax  Income Tax  Insurance   Pay  " << endl;
  fout << " ------- ------  --------  ----------  ----------  ---------  ----- " << endl;


  //loop through all input, calculation, and output
  
  while( !fin.eof() )
  { 
    fin >> inSales >> inHours >> inDep;
    fin.ignore(80, 10);

    plan = PickaPlan(inSales, inHours, planA, planB);

    OutputandRecord(inSales, inHours, inDep, plan, fout, planA, planB);

  }

  cin.get();
  cin.get();
  return 0;

}
      
char PickaPlan(float sales, int hours, float * planA, float * planB)
{
  
  //this is where exception occurs
  *planA = hours * PAY_RATE;

  //overtime calculation
  if (hours > 40)
    {
      hours -= 40;
      *planA += hours * ( PAY_RATE * .5);
    }

  *planA += sales * COMMISSION_RATEA;

  *planB = sales * COMMISSION_RATEB;
  
  if(*planA > *planB)
    return 'A';
  else
    return 'B';
}

void OutputandRecord(float sales, int hours, int dependents, char plan, ofstream& fout, float * planA, float * planB)
{
    float grosspay, social_sec, state_tax, fed_tax, netpay;
    int insurance = 25;

    if(plan == 'A')
      grosspay = *planA;
    else
      grosspay = *planB;

    
    social_sec = grosspay * SOC_SEC_RATE;
    state_tax = grosspay * STATE_TAX;
    fed_tax = grosspay * FED_TAX;
    

    if(dependents >= 3)
      insurance += 10;
    
    netpay =  grosspay - (social_sec + state_tax + fed_tax + insurance);

    //formatting output to fit under headings in header above in main

    fout << 
      setw(8) << grosspay << setw(7) << plan << setw(10) << social_sec << setw(12) << state_tax
      << setw(12) << fed_tax << setw(11) << float(insurance) << setw(7) << netpay << endl;

    cout <<
      setw(8) << grosspay << setw(7) << plan << setw(10) << social_sec << setw(12) << state_tax
      << setw(12) << fed_tax << setw(11) << float(insurance) << setw(7) << netpay << endl;
}

I experimented with your code and I think a problem might be that you are declaring, but possibly not setting aside memory for

float* planA;
float* planB;

When I put these two lines at the top of the function:

planA = new float;
planB = new float;

the program didn't crash. It went into an infinite loop, but it did not crash.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.