Storing 20 sets of 3 numbers into an array

I have been looking for a couple of days online and I am stuck on getting my 20 pairs of 3 randomly generated numbers stored in array. I need to sum them eventually and then sort them to show the top 2 scores along with the bottom two scores. The entire code is posted, but specifically lines 29-35. Thanks in advance.

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
  //Chapter 8 lab, Dancing with the stars
#include <iostream>
#include <vector>
#include <ctime>
#include <cstdlib>

using namespace std;

//prototype
int scores(int seed, int count);

 	//Seed the random
unsigned seed = time(0);

int main() {
    
    //header
    cout << "\t" << "  Welcome to Dancing with the Stars!" << endl;
    cout << endl;
    cout << "\t\t" << "  Judges Scores:" << endl;
    cout << "\t\t" << "-----------------" << endl;
    cout << "\t\t" << "#1" << "\t" << "#2" << "\t" << "#3" << endl;
    cout << "\t\t" << "-----------------" << endl;

    //print judges scores
for(int z = 1; z <= 20; z++)
    scores(z, 3);
	
	//array to store the 3 scores
	int sumScores[20];
	    for (int i=0; i <= 20; i++)
	{
	    sumScores[i]=i;  //store a number in each array element
	    cout << "sumScores[" << i << "] = " << sumScores[i] << endl;
	}
                
	
system("pause");
return 0;
}


    //function for random numbers(scores)
int scores(int seed, int count) {
	srand(seed);
	
    cout << "Pair: " << seed;
	for(int index = 1; count >= index; index++)
		cout << "    \t" << ((rand() % 10) + 1);
	cout << endl; 
	
	return count;
}
Last edited on
If i understand correctly, and i'm not sure i do, make a little class or struct.

1
2
3
4
5
6
7
class ScoreRound
{
public:
	int m_Judge1Score;
	int m_Judge2Score;
	int m_Judge3Score;
};


then all you need is an array of these objects.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main()
{
	const int numRounds = 20;

	ScoreRound scores[numRounds];

	for(int i=0;i<numRounds;++i)
	{
		// store numbers away for each judge.
		// i've just used random values
		scores[i].m_Judge1Score = 2;
		scores[i].m_Judge2Score = 8;
		scores[i].m_Judge3Score = 6;

	}	

	return 0;
}
Last edited on
We haven't discussed classes yet. I would like to use a for loop to take the 60 generated numbers and then put them into an array. Here is the code I have but the output is nothing close to what I want...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    //function for random numbers(scores)
int scores(int seed, int count) {
int firstRound[60];	
	
    cout << "Pair: " << seed;
	for(int index = 1; count >= index; index++){
		cout << "    \t" << ((1 + rand() % 10));
	cout << endl; 
}
		//array to store the 3 scores
	    for (int i = 0; i <= 60; i++){

		for (i = 0; i <= 60; i++ )
			cout << firstRound[i] << endl;
		return 0;
	        
	}
	return count;
Topic archived. No new replies allowed.