| | |
Help with unhandled exception
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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
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
c++ Syntax (Toggle Plain Text)
#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; }
Bazoo will prevail!!
•
•
Join Date: Jan 2008
Posts: 3,828
Reputation:
Solved Threads: 501
I experimented with your code and I think a problem might be that you are declaring, but possibly not setting aside memory for
When I put these two lines at the top of the function:
the program didn't crash. It went into an infinite loop, but it did not crash.
C++ Syntax (Toggle Plain Text)
float* planA; float* planB;
When I put these two lines at the top of the function:
C++ Syntax (Toggle Plain Text)
planA = new float; planB = new float;
the program didn't crash. It went into an infinite loop, but it did not crash.
![]() |
Similar Threads
- acces violation while trying to catch an exception by reference (C++)
- Unhandled Excepton (Java)
- An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system. (VB.NET)
- An unhandled exception of type 'System.Net.Sockets.SocketException' error (ASP.NET)
- I need help with a Security Exception (ASP.NET)
- Unhandled exception in IEXPLORER.EXE (SHDOCVW.DLL): 0xC0000005: Access Violation (Web Browsers)
- Recursive Hash map - unhandled exception help (C)
- loads htm but not aspx (ASP.NET)
- Error when installing some .exe programs (Windows 95 / 98 / Me)
- Create Windows Authentication (VB.NET)
Other Threads in the C++ Forum
- Previous Thread: Array to .txt file
- Next Thread: What is the Output?
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






