I need a little help with the code please

Here is the code i have right now:

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
  #include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;


void welcomeMsg()
{
	cout << "Welcome to my program";
	cout << endl;

}




double totalPay(string workerName, int numOFHours, int hourlyRate, int stateTax, int fedTax)
{
	double grossPay, netPay;

	grossPay = (numOFHours * hourlyRate);
	netPay = grossPay - ((grossPay * (stateTax / 100)) + (grossPay * (fedTax / 100)));


	return netPay;
}

void showResults(string workerName, double numOFHours, double hourlyRate, double stateTax, double fedTax)
{
	double grossPay, netPay;

	grossPay = (numOFHours * hourlyRate);
	stateTax = grossPay * (stateTax / 100);
	fedTax = grossPay * (fedTax / 100);
	netPay = grossPay - (stateTax + fedTax);

	cout << workerName << " works for " << numOFHours << "Hours for " << hourlyRate << "$ /Hour ," << endl;
	cout << "State Tax of " << stateTax << " and Federal Taxes of " << fedTax << endl;
	cout << "The worker gets: " << grossPay << "$ and netpay of: " << netPay << "$";

}


double grossPay(string workerName, int numOFHours, int hourlyRate, int stateTax, int fedTax)
{
	double grossPay;

	grossPay = (numOFHours * hourlyRate);

	return grossPay;
}



int main()
{
	int numOFHours, stateTax, fedTax, N = 1, numOfWorkers;
	double hourlyRate, totalGrossPay, averageGrossPay;
	string workerName;
	char addAnotherOne;

	welcomeMsg();

	do
	{
		cout << endl << "please enter the number of workers you want to calculate: ";
		cin >> numOfWorkers;




		for (int f = 0; f < numOfWorkers; f++)
		{

			cout << "Please enter worker" << N << " name: ";
			cin >> workerName;
			N = N++;

			do
			{
				cout << "Please enter the number of hours worked: ";
				cin >> numOFHours;

				if (numOFHours < 0)
				{
					cout << "You entered invalid number, please reenter valid number";
				}

				if (numOFHours > 60)
				{
					cout << "Maximum number of hours is 60";
				}
			} while ((numOFHours < 0) || (numOFHours > 60));



			do
			{
				cout << "Please enter hourly pay rate: ";
				cin >> hourlyRate;

				if (hourlyRate <= 0)
				{
					cout << "You entered invalid number, please reenter valid number";
				}

				if (hourlyRate > 42.47)
				{
					cout << "Maximum hourly rate is 42.47";
				}
			} while ((hourlyRate <= 0) || (hourlyRate > 42.47));



			do
			{
				cout << "Please enter the percentage of you state tax: ";
				cin >> stateTax;

				if (stateTax < 0)
				{
					cout << "You entered invalid number, please reenter valid number";
				}

				if (stateTax > 10)
				{
					cout << "Maximum state tax is 10%";
				}

			} while ((stateTax < 0) || (stateTax > 10));



			do
			{
				cout << "Please enter the percentage of you Federal tax: ";
				cin >> fedTax;

				if (fedTax < 0)
				{
					cout << "You entered invalid number, please reenter valid number";
				}

				if (fedTax > 25)
				{
					cout << "Maximum Federal tax is 25%";
				}

			} while ((fedTax < 0) || (fedTax > 25));



			showResults(workerName, numOFHours, hourlyRate, stateTax, fedTax);
			cout << endl;
			totalGrossPay += totalPay(workerName, numOFHours, hourlyRate, stateTax, fedTax);
		}

		cout << endl;
		averageGrossPay = (totalGrossPay / numOfWorkers);
		cout << "There are " << numOfWorkers << " workers with total gross pay of " << totalGrossPay << "$ and average gross pay of " << averageGrossPay << "$" << endl << endl;

		cout << "Do you need to add another worker? y/n" << endl;
		cin >> addAnotherOne;

	} while (addAnotherOne != 'n');
	system("PAUSE");
	return 0;
}



but i do want to sort the workers that the user enter in descendant order, how can i do it, what to add or modify

thank you
Could you elaborate? What do you mean by

but i do want to sort the workers that the user enter in descendant order
lets say the user entered 5 workers and their pay
i want to sort their pay at the end like this :
1) worker1 with 100$
2) worker2 with 90$
3) 80$

and so on
In that case. You can create an array of workers. Then each time they enter a worker name, place it in the index. For example, if you had

1
2
cout << endl << "please enter the number of workers you want to calculate: ";
		cin >> numOfWorkers;


Create the array -
 
string* worker = new string[numOfWorkers];


Then here -

1
2
3
4
5
6
for (int f = 0; f < numOfWorkers; f++)
		{

			cout << "Please enter worker" << N << " name: ";
			cin >> workerName;
                        worker[f] = workerName;


You could Put every worker in the array.

Exact same process for the money. Then at the end just print them all out with a for-loop.
alright i will do,
thanks bud
Goodluck to you. If there is any more trouble just post it here.
Topic archived. No new replies allowed.