struct

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 #include <iostream>
#include <string>
using namespace 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()
{
const int 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);
when the hours or rate is negative

IF (hours is negative OR rate is negative) THEN break
Last edited on
Topic archived. No new replies allowed.