Help with multiple arrays!!!

Hi all,

For my assignment, I need to add the job name, actor name and salary for a casting agency. I guess the multiple array here would be the job name and actor name. I'm stuck at this part: talent[jobname][talentname] = ???. How do I save this data as well as salary into this array?

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
 #include <iostream>
#include <string>

using namespace std;

int main()
{
	string talent [100][1000];
	double sal [1000];
	int count = 0;

	int choice = 1;
	while (choice != 0)
	{
		cout << endl;
		cout << "1 - Add a New Record" << endl;
		cout << "2 - Display Talents by Job" << endl;
		cout << "3 - Display All" << endl;
		cout << "0 - Exit" << endl;
		
		cout << "What do you want to do: ";
		cin >> choice;

		if (choice == 1)
		{

		}
		else if (choice == 2)
		{

		}
		else if (choice == 3)
		{

		}
		else if (choice == 0)
		{
			cout << "Bye bye!" << endl;
		}
	}
	system("PAUSE");
	return 0;
}

void addrecord(string talent[100][1000], double sal[1000], int &count)
{
	string jobname;
	cout << "Enter job name: ";
	cin >> jobname;

	string talentname;
	cout << "Enter talent name: ";
	cin >> talentname;

	double payment;
	cout << "Enter payment: ";
	cin >> payment;

	talent[jobname][talentname] = 
}
Why not just use parallel arrays for this project? Instead of a multi-dimension array. Assuming you can use structs or classes yet.
Motobus, yeah I realized I was overthinking it quite a bit, haha. Thanks for putting me back on track and saving me a headache!

another question now though, I'm trying to find the average of salaries of people with the same job name, however, I'm not sure how to set the denominator up. When I use i, the average just displays as the total. How can I fix this?


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
void search(string jobName[], string talentName[], double salary[], int count)
{
	// Get User Inputs
	string jobname;
	cout << "Enter job name: ";
	cin >> jobname;

	// Declaration of Variables
	double total = 0;
	double high = -9999;
	double low = 9999;
	double average = 0;

	bool found = false;

	for (int i=0; i < count; i++)
	{
		if (jobName[i] == jobname)
		{
			cout << talentName[i] << " paid $" << salary[i] << endl;
			found = true;
			total += salary[i]; // sum of all salaries with jobName[i]
			average = total/i; // average of all salaries with jobName[i]
			if (high < salary[i])
			{
				high = salary[i]; // high of all salaries with jobName[i]
			}
			if (low > salary[i])
			{
				low = salary[i]; // low of all salaries with jobName[i]
			}
		}
	}
Just make a separate counter variable. Each time to find the jobName you are searching for increment it then use that to divide into your total to get your average.
Topic archived. No new replies allowed.