I have this assignment for school due tonight but I can't figure out the two errors causing problems for me. I've asked my class, I've asked twice on yahoo answers and I still don't understand what to change. If someone can please show me the exact changes that need to be made and explain them in the simplest terms I would be eternally grateful. Thanks in advance. Here's my code and the build output.

1. #include <iostream>
2. #include<string>
3. #include<iomanip>
4. using namespace std;
5.
6. int inputData(char[][50], int[], int&, int&);
7. int displayData(char[][50], int[], int);
8.
9. int main()
10. {
11. char playerName [100][50] = {0};
12. int score [100] = {0};
13. int numOfPlayers = 0;
14. int average = 0;
15. inputData(playerName, score, numOfPlayers, average);
16. displayData(playerName, score, numOfPlayers);
17.}
18. int inputData (char playerName[][50], int score[100], int &numOfPlayers, int &average)
19. {
20. while (numOfPlayers < 100)
21. {
22. cout <<" Enter Players Name(Q to quit) :";
23. cin >> playerName[numOfPlayers];
24. if (playerName[numOfPlayers][0] == 'Q') break;
25. cout << " Enter score:";
26. cin >> score[numOfPlayers];
27. numOfPlayers += 1;
28. average += score[numOfPlayers];
29. }
30. int belowAverage[50] = {0};
31. average = average / numOfPlayers;
32 for ( int i = 0; i < average; i++)
33. {
34. belowAverage = average[i];
35. }
36. if (score[i] < average)
37. score = belowAverage;
38. return 0;
39. }
40.
41. int displayData(char playerName[][50], int score[100], int numOfPlayers)
42. {
43. for (int index = 0; index < numOfPlayers; index++)
44. {
45. cout << "Player Name: " << playerName[index] << endl;
46. cout << "Score: " << score[index] << endl;
47. cout << endl;
48. }
49. return 0;
50.}

1>------ Build started: Project: LAB5A, Configuration: Debug Win32 ------
1>Compiling...
1>Lab5A.cpp
1>lab5a.cpp(34) : error C2109: subscript requires array or pointer type
1>lab5a.cpp(36) : error C2065: 'i' : undeclared identifier
1>LAB5A - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

PS: This is my first time posting, on here and I'm not entirely sure how to use the code tags properly, sorry if that is wrong.

average is not an array. You can't take the i-th member of something that only has one value. What are you trying to accomplish with that line?

The variable 'i' is undeclared on line 36 because it is outside of the for loop. Look up variable scope.

Where do I declare 'i' exactly? In int Main()? I'm not good at coding at all.

Since average is not an array, what do you need i for?

Ok that made a light bulb go off. I moved the i over to below average so it now reads:

for ( int i = 0; i < average; i++)
	{
		belowAverage[i] = average;
	}
	if (score[i] < average)
		score = belowAverage;

Which leaves with me with the error

lab5a.cpp(36) : error C2065: 'i' : undeclared identifier

I tried removing the 'i' completely but then it gives me 3 errors. Any idea of what I should do with it now? I tried declaring it but it's not working

Ok nevermind that. I actually fixed it. Now I can't get it to display the average scores or anything like that.

Edited 5 Years Ago by Jutch: n/a

Random suggestion: could typedef your array so as to help ensure consistency.

typedef char matrix_type[100][50];
int foo(matrix_type m);

I finally got it all to work. Thank you all very much for the help.

This article has been dead for over six months. Start a new discussion instead.