I am writing a program in c++ that calculates overtime hours worked. For some reason the calculation of overtime_hours_worked
is way off. I tried initializing variable and negation. I inputted 48 hours for hours_worked_inweek and by my formula I should be getting 8 as the answer. Instead I am getting -40. I am currently learning.
#include<iostream>
using namespace std;
int main(){
int hours_worked_inweek=0;
int dependents;
int union_dues;
double federal_tax_witholding;
double state_tax_witholding;
double social_security_tax_witholding;
double gross_pay;
double net_pay;
double hourly_rate;
double overtime_rate;
int overtime_hours_worked=0;
overtime_rate = 1.5*overtime_hours_worked;
hourly_rate = 16.76;
union_dues = 10;
overtime_hours_worked = hours_worked_inweek-40;
cout << " How many hours have you worked in a week ? " << endl;
cin >> hours_worked_inweek;
cout << "Wow ! You worked "<<hours_worked_inweek<<" this week"<<endl;
if (hours_worked_inweek>40){
cout<<"It looks like you also worked some overtime hours this week! Your Overtime hours are : "<<endl;
cout<<hours_worked_inweek<< "-" << "40" << " Which is equal to " << overtime_hours_worked<<endl;
}
else{
cout<< " You did not work any overtime hours this week !"<<endl;
}
cout<< "How many dependents do you have : "<<endl;
cin>>dependents;
return 0;
}