cout<< "Enter the total hours worked by employee. \n";
cin >> hours;
while InvalidPayRate(payrate)
{
cout << "The valid value for pay rate is in the range. \n";
cout << " of $7.50 through $ 18.25. \n";
cout << "Enter a valid value for pay rate. \n";
cin >> payrate;
}
while InvalidHours(hours)
{
cout << "Please enter hours worked between 0 and 40. \n ";
cin >> hours;
}
gross = payrate * hours;
cout << "The gross pay of the employee is $ " << gross;
}
ERRORS:
F:\CH7Q1Payroll.cpp||In function 'int main()':|
F:\CH7Q1Payroll.cpp|34|error: expected '(' before 'InvalidPayRate'|
F:\CH7Q1Payroll.cpp|34|error: 'InvalidPayRate' was not declared in this scope|
F:\CH7Q1Payroll.cpp|35|error: expected ')' before '{' token|
F:\CH7Q1Payroll.cpp|42|error: expected '(' before 'InvalidHours'|
F:\CH7Q1Payroll.cpp|42|error: 'InvalidHours' was not declared in this scope|
F:\CH7Q1Payroll.cpp|43|error: expected ')' before '{' token|
int main()
{
double payrate, hours, gross;
cout << "Enter the employees hourly pay rate. \n";
cin >> payrate;
cout<< "Enter the total hours worked by employee. \n";
cin >> hours;
while (payrate > 18.25 || payrate < 7.5)
{
cout << "The valid value for pay rate is in the range. \n";
cout << " of $7.50 through $ 18.25. \n";
cout << "Enter a valid value for pay rate. \n";
cin >> payrate;
}
while (hours > 40 || hours < 0)
{
cout << "Please enter hours worked between 0 and 40. \n ";
cin >> hours;
}
gross = payrate * hours;
cout << "The gross pay of the employee is $ " << gross;
}
But "Real" is not an integer type in the first place, so it is not usable at all. You must be leaving out some of the code. Otherwise try "float" instead of double? You must have learned one of those just to be able to complete this.
Nope. No "float". No "double". Guess how much fun it is to ask your teacher why your program will not compile and their response is "mmm... I do not know. We will need to look it up."
The "Real" did not change anything when it compiled but I did not know it was something that was not usable.
If your professor is telling you not to use floats and doubles, then he's obviously not qualified to tell you to write a program that can only operate using floats and doubles.
Mabey you could write your own floating point number class, or "have classes not been taught" yet? ;)
In any case, get points docked off your project: use a double. Your professor is wrong for thinking you can perform finance calculations on integers, lol.
Haha there it is, although all of that is pretty weird to be adding in as it teaches improper syntax... but I suppose your teacher must know what (s)he is doing? Good luck.
squirrel27:
I highly advise you not use those. They don't actually make any difference in how the code is executed (absolutely none, they are only there for asthetic purposes), and you will never see them in the field (if you do, it will be rare).
That said, if you get docked points for useing double instead of Real, then you should tell your proffessor there is no difference between a double, and a preprocessor directive that replaces "Real" with double.