I'm writing a program that will display an employee's information (pre-defined), i.e., first name, last name, age, id number, gross salary, tax amount and net salary after entering an id number and the amount of hours worked. Pretty basic yea?
My problem is that I can't get the compiler to perform the right calculations to give me gross salary, tax amount and net salary after accepting the work hours.
Based on what I'm seeing the problem is that the main variable involved in these calculations, i.e., totalHoursWorked is based on user input.
If I declare that same variable and assign it an amount, then the calculations run smoothly and output the correct value, but that's a problem because the user needs to be able to enter any value from .1 to 40 (signifying a maximum of 40 work hours).
However, the moment I remove the assigned value and ask for user input, everything goes wrong.
Below I've written the part of the code I'm having problems with. It was just a rough draft to help me visualize where the problem was and focus on tweaking it:
#include <iostream>
using namespace std;
int main()
{
double hourlyRate=7.5;
double taxPercentage=0.16;
double totalWorkHours;
double grossSalary=hourlyRate*totalWorkHours;
double taxAmount=grossSalary*taxPercentage;
double netSalary=grossSalary-taxAmount;
cout<<"Please enter total work hours"<<endl;
cin>>totalWorkHours;
cout<<grossSalary <<endl;
cout<<taxAmount <<endl;
cout<<netSalary <<endl;
system ("pause");
return 0;
}
This is the output I get:
Please enter total work hours
40 <----i input 40 here
3.95253e-323 <--- These are the results of the calculations
4.94066e-324
3.45846e-323
Press any key to continue..._