This is my latest code
It does not have an error, but i cannot calculate the rate of overtime 4O hours.
i am still running my exercise and need help.
Code:
//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>
using namespace 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 = new char[1024];
empname = new char[50];
test = new char[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.";
else if(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";
else if(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;
}