Shwing only First Unlucky Employee

why its showing only First unlucky Employee

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<iostream>
using namespace std;

 
void getInput(int[][2],int);
void netSalary(int[][2],int);
void unLucky(int[][2],int[],int);
void displayUnlucky(int[][2],int[],int);
main()
{
const int arraySize= 100;

int sal[arraySize][2];
int lucky[100] = {0};
int numEmps;

//Promt User To Enter Number Of Employees
cout<<"Please Enter Total Number Of Employees: ";	
cin>>numEmps;

getInput(sal,numEmps);			//Calling Function To Get Input
netSalary(sal,numEmps);			//Calling Function To Calculate Net Salary 
unLucky(sal,lucky,numEmps);		//Calling Function To Find UnLucky Employee
displayUnlucky(sal,lucky,numEmps);	//Calling Function To Display OutPut

}

void getInput(int sal[][2], int numEmps)	//Function To get Input
{
	for(int i = 0; i<numEmps; i++)
	{	cout<<"Please Enter Salary On Employee No "<<i +1<<": ";
		cin>>sal[i][0];
		cout<<endl;
	}
}

void netSalary(int sal[][2], int numEmps)
{
	for(int i = 0; i <numEmps; i++)
	{
		if(sal[i][0] <= 5000)
		{
			sal[i][1] = sal[i][0];
		}
		else if(sal[i][0] <= 10000)
		{
			sal[i][1] = sal[i][0] - 0.05*sal[i][0];
		}
		else if(sal[i][0] <=20000)
		{
			sal[i][1] = sal[i][0] - 0.1*sal[1][0];
		}
		else
		{
			sal[i][1] = sal[i][0] - 0.15*sal[i][0];
		}
	}		
}

void unLucky(int sal[][2], int lucky[], int numEmps)
{
/*
int i,j;
int grossSalary,netSalary;
grossSalary = sal[1][0];
netSalary = sal[i][1];
*/	
	for(int i = 0; i< numEmps; i++)
	{
		for(int j = 0; j< numEmps; j++)
		{
			if(sal[i][0] > sal[j][0] && sal[i][1] < sal[j][1])
			{
				lucky[i] = 1;
				break;
			}
		}
	}
}

void displayUnlucky(int sal[][2], int lucky[], int numEmps)
{
		for(int i = 0; i <numEmps; i++)
	
		{
			if(lucky[i]== 1)
			{
				cout<<"Employee No. <<"<<i+1<<" Is Unlukcy, Gross Salary = "
				<<sal[i][0]<<" Net Salary = "<<sal[i][1]<<endl;
			}
		}
	
}  
print the whole thing out after netsalary is called in main. I suspect your logic to load unlucky isn't doing what you expect, or possibly, you don't know what the answer is supposed to be for your data (?)? Did you work out by hand what you expect?
Last edited on
yes Thanks i was not know the answer supposed to be for my data
Topic archived. No new replies allowed.