Segmentation Fault

I code is having segmentation fault but i don know how to fix it. I need some help. Thank you.

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

int calculate_total(double&, double&, double&);
int win(double[], double&);

int main()
{
	double diver_score[7];
	double total;
	double difficulty;
	double total_score;
	double highest_score = 0;
	double diver[5];

	for (int i= 1; i <= 5; i++)
	{
		cout <<" Diver "<< i <<endl;

		for (int j = 1; j <= 7; j++)
		{
			cout << " Enter score that given by judge " << j <<"(1-10): ";
			cin >> diver_score[j];

			while (diver_score[j] < 0 || diver_score[j] > 10)
			{
				cout << " Invalid score, please again: ";
				cin >> diver_score[j];
			}

			total = total + diver_score[j];
		}

		cout << " Difficulty range (1.2 - 3.8)";
		cin >> difficulty;

		while (difficulty < 1.2 || difficulty > 3.8)
		{
			cout << " Invalid difficulty range, please enter again: ";
			cin >> difficulty;
		}

		calculate_total(total, difficulty, total_score);
		cout << "Total score : " << total_score << endl;
		diver[i] = total_score;

		total_score = 0;
		total = 0;
	}

	win(diver, highest_score);
	return 0;

}

int calculate_total(double& total, double& difficulty, double& total_score)
{
	total_score = total * difficulty * 0.6;
	return total_score;
}

int win(double diver[], double& highest_score)
{
	int participants;
	highest_score = diver[5];
	for (int x = 1; 1 <= 5; x++)
	{
		if (diver[x] > highest_score)
		{
			highest_score = diver[x];
		}
	}

	cout << " Diver " << participants << " has won with the score of : " << highest_score << endl;

	return 0;
}

Array indices start counting from zero. Valid indices for an array of size 7 is 0, 1, 2, 3, 4, 5 and 6 (but not 7).
Last edited on
It still does't not work.
In addition to all the for loops you also need to change line 65.
Last edited on
Topic archived. No new replies allowed.