This is just an exercise.
And i need to complete this.
This is the question :
Write a program in C++ that calculates the amount to be paid to an employee based on the hours worked and rate per hour. A user will enter hours worked and rate per hour for an employee. Your program should have a function payCheck that calculates and returns the amount to be paid. The formula for calculating the salary amount is as follows: for the first 40 hours, the rate is the given rate (the rate that a user has entered); for hours over 40, the rate is 1.5 times the given rate.
i had write my own coding, but it keeps error. it is okay. But i still don't think i could share here?
Still running, but anyone can help me?
i will update my coding for you alls to check for any syntax or logic error.
UPDATE : this is my coding.
The problem is i need to calculate if the employee work for more than 40 hours which 1.5 times.
//Write a program in C++ that calculates the amount to be paid
//to an employee based on the hours worked and rate per hour.
//A user will enter hours worked and rate per hour for an employee.
//Your program should have a function payCheck that calculates and
//returns the amount to be paid. The formula for calculating
//the salary amount is as follows: for the first 40 hours,
//the rate is the given rate (the rate that a user has entered);
//for hours over 40, the rate is 1.5 times the given rate.
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <iostream.h>
usingnamespace std;
int main(void)
{
char *empname, *test, *final_output;
float hours=0, pay_rate=0, emprate=0;
float pay_rate_overtime=1.5;
//variable
final_output = newchar[1024];
empname = newchar[50];
test = newchar[10];
//loop
do {
cout << "\nPlease Enter Your Name : ";
cin >> empname;
do {
cout << "\nEnter Your Pay Rate : ";
cin >> test;
if (test == NULL)
cout << "Invalid pay rate.";
elseif(atof(test) != 0)
break;
else
cout << "please enter digit only";
}
while (1);
pay_rate=atof(test);
do {
cout << "\nEnter Your Worked Hours: ";
cin >> test;
if (test == NULL)
cout << "please enter digit only";
elseif(atof(test) != 0)
break;
else
cout << "Invalid amount of hours.";
}
while (1);
hours=atof(test);
/*-- calculate values --*/
emprate=hours*pay_rate;
/*-- set out precision --*/
cout.precision(2);
cout.setf(ios::fixed | ios::showpoint);
/*-- create output --*/
sprintf(final_output,"\n\n Your Pay Rate is : \n------------------------------\n", empname);
cout << final_output;
cout << "Your Salary Is : " << emprate <<endl;
/*-- do another? --*/
cout << "\n\n Calculate Another? (y/n)?";
cin >> test;
/*-- check first value of string for y/Y --*/
} while (!strncasecmp(test,"y",1));
/*-- return memory to the heap --*/
delete [] empname;
delete [] test;
return 0;
}
you should first be checking whether hours is greater than 40.
If so, would then split this into
normal_hours = 40
overtime_hours = hours - normal_hours
//Write a program in C++ that calculates the amount to be paid
//to an employee based on the hours worked and rate per hour.
//A user will enter hours worked and rate per hour for an employee.
//Your program should have a function payCheck that calculates and
//returns the amount to be paid. The formula for calculating
//the salary amount is as follows: for the first 40 hours,
//the rate is the given rate (the rate that a user has entered);
//for hours over 40, the rate is 1.5 times the given rate.
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <iostream.h>
usingnamespace std;
int main(void)
{
char *empname, *test, *final_output;
float hours=0, pay_rate=0, emprate=0;
float pay_rate_overtime=1.5;
//variable
final_output = newchar[1024];
empname = newchar[50];
test = newchar[10];
//loop
do {
cout << "\nPlease Enter Your Name : ";
cin >> empname;
do {
cout << "\nEnter Your Pay Rate : ";
cin >> test;
if (test == NULL)
cout << "Invalid pay rate.";
elseif(atof(test) != 0)
break;
else
cout << "please enter digit only";
}
while (1);
pay_rate=atof(test);
do {
cout << "\nEnter Your Worked Hours: ";
cin >> test;
if (test == NULL)
cout << "please enter digit only";
elseif(atof(test) != 0)
break;
else
cout << "Invalid amount of hours.";
}
while (1);
hours=atof(test);
/*-- calculate values --*/
emprate=hours*pay_rate;
/*-- set out precision --*/
cout.precision(2);
cout.setf(ios::fixed | ios::showpoint);
/*-- create output --*/
sprintf(final_output,"\n\n Your Pay Rate is : \n------------------------------\n", empname);
cout << final_output;
cout << "Your Salary Is : " << emprate <<endl;
/*-- do another? --*/
cout << "\n\n Calculate Another? (y/n)?";
cin >> test;
/*-- check first value of string for y/Y --*/
} while (!strncasecmp(test,"y",1));
/*-- return memory to the heap --*/
delete [] empname;
delete [] test;
return 0;
}
Why did you copy your earlier post? Chervil kindly offered you a solution in his reply, yet I don't see that in your code. If you require further help, please state your problem clearly and specifically.