PLEASE Masters of C++~~

I'm a beginner (3wks into C++)
Payroll program is due in 1hour.
I can't figure out what is wrong with my program.
it compiles, builds, and runs but when I enter the name, it goes straight to the end of the program.
heres the code


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

using namespace std;

int main()
{


float LName, FName, ID, TotalHours, PayRate, RegularHours, OvertimeHours, GrossPay, RegularPay, OvertimePay, FedTax, StTax, NetPay;

cout<<"Enter Last Name: ";
cin>>LName;
system("cls");
cout<<"Enter First Name: ";
cin>>FName;
system("cls");
cout<<"Enter ID #: ";
cin>>ID;
system("cls");
cout<<"Enter Total Hours Worked(Maximum of 60 hours): ";
cin>>TotalHours;
system("cls");
cout<<"Enter Pay Rate: ";
cin>>PayRate;
system("cls");


if( TotalHours < 40 )
{
RegularPay = TotalHours * PayRate;

}
else if( TotalHours >= 40 )
{
RegularHours = 40;
RegularPay = PayRate * 40;
OvertimeHours = TotalHours - 40;
OvertimePay = OvertimeHours * PayRate * 2;
}

if( TotalHours > 60 )
{
cout<<"You Have Entered above Maximum Hours";
}


FedTax = GrossPay * 0.20;
StTax = GrossPay * 0.05;
GrossPay = RegularPay + OvertimePay;
NetPay = GrossPay - FedTax - StTax;

cout<<"\nLast Name: "<<LName<<"First Name: "<<FName<<"ID#: "<<ID;
cout<<"\nTotal Hours: "<<TotalHours<<"Regular Hours: "<<RegularHours<<"Overtime Hours: "<<OvertimeHours<<"Pay Rate: "<<PayRate;
cout<<"\nNetpay"<<GrossPay<<" - "<<FedTax<<"-"<<StTax<<"="<<NetPay;


cout<<"\nHit any key to continue..";

getch();
return 0;


}

</code>
So close with the code tags. It's actually [code], not <code>.

Anyway your problem is here:

 
float LName, FName


If LName and FName are floats, then they hold a floating point number. Names are not floating point numbers, they're strings.

So you probably want to change those to strings.
Also, GrossPay is used before it is initialized. Consider reordering these lines:
1
2
3
FedTax = GrossPay * 0.20;
StTax = GrossPay * 0.05;
GrossPay = RegularPay + OvertimePay;


BTW, 1 hour before its due isn't exactly a great time to post an issue. You got lucky.
Last edited on
THANK YOU SO MUCH GUYS!!!!!!!
WITH YOUR ADVICES, I JUST FINISHED IT 3 MINS BEFORE DEADLINE!!
Just one more thing..
Howcome my program did not limit the maximum hours of 60?
did I use wrong statement?
You forgot the else and return:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
if( TotalHours < 40 )
{
RegularPay = TotalHours * PayRate;

}
else if( TotalHours >= 40 )
{
RegularHours = 40;
RegularPay = PayRate * 40;
OvertimeHours = TotalHours - 40;
OvertimePay = OvertimeHours * PayRate * 2;
}

else if( TotalHours > 60 )
{
cout<<"You Have Entered above Maximum Hours";
return 0;
}

You should have seen the message but it let's you continue as is.
Last edited on
The first "else-if" needs to have a test to see if the TotalHours are less than or equal to 60:

else if( TotalHours >= 40 && TotalHours <= 60 )

otherwise, the code will never reach the last "else-if" statement.
I guess it doesn't even need the else, just the return...
Masters of C++~~
 Disch
 moorecm
 kooth


just having fun ^^
Topic archived. No new replies allowed.