Star Search (Now with arrays)

Hello, I am needing some serious help on this. I don't understand how to use arrays at all, and I don't know how to use functions well either. The intended goal is to put the scores into the array. Any help will be greatly appreciated.


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
#include <iostream>
#include <iomanip>
using namespace std;

double getScore( double maxScore );
bool isValid( double theScore, double maxValue );


double getSmallest(double theArray [], int theSize);
void displayArray(int theArray[], int theSize);
int sumArray(const int theArray[], int theSize);
int averageArray(const int theArray[], int theSize);
int findLargest(const int theArray[], int theSize);
int findSmallest(const int theArray[], int theSize);
void scoreArray(int theArray[], int theSize);

int main()
{
    
    const double MAX_SCORE = 10;
    cout << "Please enter the 5 judge scores" << endl;
    
    const double s1 = getScore(MAX_SCORE);
    const double s2 = getScore(MAX_SCORE);
    const double s3 = getScore(MAX_SCORE);
    const double s4 = getScore(MAX_SCORE);
    const double s5 = getScore(MAX_SCORE);

	const int SIZE = 5;

	int tests[SIZE] = { 0 };

	displayArray(tests, SIZE);
	
	return 0;
}

//Array Stuff

int averageArray(const int theArray[], int theSize) {
	return sumArray(theArray, theSize) / theSize;
}

int sumArray(const int theArray[], int theSize) {
	int sum = 0;

	for (int i = 0; i < theSize; i++) {
		sum += theArray[1];
	}

	return sum;
}


void displayArray(int theArray[], int theSize) {
	for (int i = 0; i < theSize; i++) {
		if (i % 10 == 0) {
			cout << endl;
		}
		cout << setw(7) << theArray[i];
	}
	cout << endl;
	cout << endl;
}


void scoreArray(int theArray[], int theSize) {
	for (int i = 0; i < theSize; i++) {
		theArray[i] = s1, s2, s3, s4, s5;
	}
}


int findLargest(const int theArray[], int theSize) {
	int result = theArray[0];
	for (int i = 1; i < theSize; i++) {
		if (theArray[i] > result) {
			result = theArray[i];
		}
	}
	return result;
}


int findSmallest(const int theArray[], int theSize) {
	int result = theArray[0];
	for (int i = 1; i < theSize; i++) {
		if (theArray[i] < result) {
			result = theArray[i];
		}
	}
	return result;
}


//Old Stuff

double getScore( double maxScore )
{
    double score ;
    cout << "Enter the judge scores: ";
    cin >> score ;

    if( isValid( score, maxScore ) ) return score ;

    cout << "Invalid score, please enter a new one.";
    return getScore(maxScore) ;
}

bool isValid( double theScore, double maxValue )
{ return theScore >= 0 && theScore <= maxValue ;}
closed account (N8MNAqkS)
Arrays are just variables that store a specified amount of info.

1
2
3
4
5
6
7
8
9
10
11
12
13

int main()
{

int ArrOne[5] = (1,2,3,4,5);
cout << ArrOne[0]; //outputs 1
cout << ArrOne[1]; //outputs 2

//The five in the box braces tells ArrOne to set aside 5 spaces, //or boxes if u will, to store data in. Then in order from left to //right inside of parentheses you tell ArrOne where to store each //number, 1 is stored in the first box, 2 is stored in the second //box, and so on and so forth.

//Real programmers start counting from 0, so that is why when you call to the number you want out of the array, you call box 0 in the box braces for the first number of the array.
}


And that is how arrays work. Although they do have some functions that go with them.

Last edited on
Topic archived. No new replies allowed.