wage calculater need help!!!!

i dont know why when i run my code the output numbers come out incorrect example the gross pay comes out as $51562255152.00 can anybody tell me why this is happening and also everything comes out clustered up how can a make them distant and understandable to read

#include <iostream>
#include <iomanip>
#include <conio.h>
#include <string>

using namespace std;
int main()
{

string lastname, firstname, empid;
int regularHours;
double totalHours, payPerhour, overTimehours, grossPay, regularPay, overTimepay, federalTaxes, stateTaxes, netPay;




cout<<" Enter employee's LAST name"<<endl;
getline(cin, lastname);
cout<<" Enter employee's FIRST name"<<endl;
getline(cin, firstname);
cout<< "Enter employee's ID Number"<<endl;
getline (cin, empid);
cout<<" Enter the employee's Total Hours worked up to a maximum of 60 hours"<<endl;
cin>> totalHours;
cout<<"Enter the employee's Pay Per Hour"<<endl;
cin>> payPerhour;

regularPay= regularHours*payPerhour;
cout<<"Regular Pay $"<<fixed<<setprecision(2)<< regularPay<<endl;


if (overTimehours> 40 && overTimehours < 60)

{

overTimepay= (overTimehours*payPerhour)*2;
cout<<"Over Time Pay $"<<fixed<<setprecision(2)<< overTimepay<<endl;

}
else
{

regularPay= regularHours*payPerhour;
cout<<"Regular Pay $"<<fixed<<setprecision(2)<< regularPay<<endl;


}


grossPay= regularPay+ overTimepay;
cout<<"Gross Pay $"<<fixed<<setprecision(2)<< grossPay<<endl;

federalTaxes= grossPay* 0.2;
cout<< "Federal Taxes Withheld @ 20%"<< federalTaxes<<endl;

stateTaxes= grossPay*0.05;
cout<< "State Taxes Withheld @ 5%"<< stateTaxes<<endl;

netPay=grossPay-federalTaxes-stateTaxes;
cout<< "Net Pay $"<< netPay<<endl;
On the line regularPay= regularHours*payPerhour; what do you think the value of regularHours is? I see that you declared it int regularHours;, but in between that declaration and where you use the value the first time... You never once give it a value. So what do you think the value is? Your answer should be: "I have no idea." The compiler that makes your program also has absolutely no idea, because in C++ variables should have a value assigned to them before their first use. Hope that helps :)
Last edited on
Topic archived. No new replies allowed.