Help with unhandled exception

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 16
Reputation: SurviBee is an unknown quantity at this point 
Solved Threads: 0
SurviBee's Avatar
SurviBee SurviBee is offline Offline
Newbie Poster

Help with unhandled exception

 
0
  #1
Feb 14th, 2008
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


  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. const double COMMISSION_RATEA = .10;
  8. const double COMMISSION_RATEB = .3;
  9. const double SOC_SEC_RATE = .06;
  10. const double PAY_RATE = 9.5;
  11. const double FED_TAX = .125;
  12. const double STATE_TAX = .08;
  13.  
  14.  
  15.  
  16. char PickaPlan(float, int, float *, float *);
  17.  
  18. void OutputandRecord(float, int, int, char, ofstream&, float *, float *);
  19.  
  20.  
  21. int main()
  22. {
  23. float inSales;
  24. int inHours, inDep;
  25. char plan;
  26.  
  27. float* planA;
  28. float* planB;
  29.  
  30. //declare fstreams and open files
  31. ifstream fin;
  32. fin.open("salary3.in");
  33.  
  34. ofstream fout;
  35. fout.open("salary3.out");
  36.  
  37. //output header
  38. cout << " Gross Plan Social State Federal Health Net " << endl;
  39. cout << " Pay Security Income Tax Income Tax Insurance Pay " << endl;
  40. cout << " ------- ------ -------- ---------- ---------- --------- ----- " << endl;
  41.  
  42. fout << " Gross Plan Social State Federal Health Net " << endl;
  43. fout << " Pay Security Income Tax Income Tax Insurance Pay " << endl;
  44. fout << " ------- ------ -------- ---------- ---------- --------- ----- " << endl;
  45.  
  46.  
  47. //loop through all input, calculation, and output
  48.  
  49. while( !fin.eof() )
  50. {
  51. fin >> inSales >> inHours >> inDep;
  52. fin.ignore(80, 10);
  53.  
  54. plan = PickaPlan(inSales, inHours, planA, planB);
  55.  
  56. OutputandRecord(inSales, inHours, inDep, plan, fout, planA, planB);
  57.  
  58. }
  59.  
  60. cin.get();
  61. cin.get();
  62. return 0;
  63.  
  64. }
  65.  
  66. char PickaPlan(float sales, int hours, float * planA, float * planB)
  67. {
  68.  
  69. //this is where exception occurs
  70. *planA = hours * PAY_RATE;
  71.  
  72. //overtime calculation
  73. if (hours > 40)
  74. {
  75. hours -= 40;
  76. *planA += hours * ( PAY_RATE * .5);
  77. }
  78.  
  79. *planA += sales * COMMISSION_RATEA;
  80.  
  81. *planB = sales * COMMISSION_RATEB;
  82.  
  83. if(*planA > *planB)
  84. return 'A';
  85. else
  86. return 'B';
  87. }
  88.  
  89. void OutputandRecord(float sales, int hours, int dependents, char plan, ofstream& fout, float * planA, float * planB)
  90. {
  91. float grosspay, social_sec, state_tax, fed_tax, netpay;
  92. int insurance = 25;
  93.  
  94. if(plan == 'A')
  95. grosspay = *planA;
  96. else
  97. grosspay = *planB;
  98.  
  99.  
  100. social_sec = grosspay * SOC_SEC_RATE;
  101. state_tax = grosspay * STATE_TAX;
  102. fed_tax = grosspay * FED_TAX;
  103.  
  104.  
  105. if(dependents >= 3)
  106. insurance += 10;
  107.  
  108. netpay = grosspay - (social_sec + state_tax + fed_tax + insurance);
  109.  
  110. //formatting output to fit under headings in header above in main
  111.  
  112. fout <<
  113. setw(8) << grosspay << setw(7) << plan << setw(10) << social_sec << setw(12) << state_tax
  114. << setw(12) << fed_tax << setw(11) << float(insurance) << setw(7) << netpay << endl;
  115.  
  116. cout <<
  117. setw(8) << grosspay << setw(7) << plan << setw(10) << social_sec << setw(12) << state_tax
  118. << setw(12) << fed_tax << setw(11) << float(insurance) << setw(7) << netpay << endl;
  119. }
Bazoo will prevail!!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,828
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Help with unhandled exception

 
0
  #2
Feb 14th, 2008
I experimented with your code and I think a problem might be that you are declaring, but possibly not setting aside memory for
  1. float* planA;
  2. float* planB;

When I put these two lines at the top of the function:
  1. planA = new float;
  2. planB = new float;

the program didn't crash. It went into an infinite loop, but it did not crash.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC