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.

#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, gross=0, net=0;

//loop
do {
/*-- get first & last name --*/
cout<<"Please Enter Your Name ";
cin>>empname;

/*--
get pay rate with error checking on
null and 0 values
--*/
do {
cout << "Pay Rate: ";
cin >> test;
if (test == NULL)
cout << "Invalid pay rate.";
else if(atof(test) != 0)
break;
else
cout << "Invalid pay rate.";
} while (1);
pay_rate=atof(test);

/*--
get hours worked with error checking on
null and 0 values
--*/
do {
cout << "Hours Worked: ";
cin >> test;
if (test == NULL)
cout << "Invalid amount of hours.";
else if(atof(test) != 0)
break;
else
cout << "Invalid amount of hours.";
} while (1);
hours=atof(test);

/*-- calculate values --*/
gross=hours*pay_rate;

/*-- set out precision --*/
cout.precision(2);
cout.setf(ios::fixed | ios::showpoint);

/*-- create output --*/
sprintf(final_output,"\n\n%s %s ssn(%s)\n------------------------------\n",
empname);
cout << final_output;
cout << "Gross: " << gross << endl;

/*-- do another? --*/
cout << "Calculate Another? (y/n)?";
cin >> test;

/*-- check first value of string for y/Y --*/
} while (!strncasecmp(test,"y",1));

return 0;
} 

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;
}
[/code]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.