first issue how i do fail the loop from calculating the company[i].pay when the hours or rate is negative.
second are my return type for function prototypes okay?
#include <iostream>
#include <string>
usingnamespace std;
struct Employee //the name of the struct
{
string eName;
double hours, rate, pay;
};
void getData (Employee[],int); //function prototypes
/*receives the array of struct, and the size of the array as parameters. Prompts the
user to input data which is stored in each element of the array. Validate that hours
and rate are positive. Call calcPay and store the pay for each employee. */
void calcPay (Employee[],int);
/* receives hours and rate for a single employee. Calculates and returns the pay.
Make sure to account for overtime, hours over 40 are paid at 1.5 times the rate.*/
void printPayroll (Employee[],int);
/*receives the array of struct, and the size of the array as parameters. Prints the
payroll report as shown below. Note that it also calculates and displays the total
payroll.*/
int main()
{
constint size = 4;
Employee company[size];
for(int i=0;i<10;i++)
{ /* reading name and test scores*/
cout<<"Enter name of the employee:";
getline(cin,company[i].eName);
cout<<"Enter the hours worked:";
cin>>company[i].hours;
if (company[i].hours<0){
cout<<"sorry the hours entered are invalid"<<endl;
}
cout<<"Enter the rate:";
cin>>company[i].rate;
if (company[i].rate<0){
cout<<"sorry nobody pays in negative"<<endl;
}
company[i].pay= company[i].rate*company[i].hours;
cout << company[i].eName<< ", your pay is $"<< company[i].pay<<endl;
cin.ignore();
}
return 0;
}
void getData (Employee company[],int size);