So I've been working on this project for quite awhile now and I can't seem to figure out how to fix all of my errors. If you could run the program, it will appear as 17 errors. So far I don't know where I could of went wrong. Any help would be appreciated even if its just suggestions/advice.
** NO Global Variables was the only thing prohibited **

Please note this code below was my rough draft, after I get all the functions to work and whatever else I will fix the cosmetic parts and will use precision code for the right amount of spaces when consoled out.

/* Developer: DaniwebOS
Date Written: January 6, 2011
Purpose: Video Game Player Program
*/

#include <iostream>
#include <conio.h>
#include <string>
using namespace std;

//All Prototypes
void InputaData(string[], int[], int, int);
void DisplayPlayerData(string[], int[], int);
double calAVGScore(int[], int);
void AvgBelowPlayerData(string[], int[], int, double);

//Main Function
int main()
{
	//Local Variable used
	const int SIZE = 100;
	int numPlayers = 0;
	double avgScore;
	
	//---
	string playerName[SIZE];
	int score[SIZE];
	InputData(playerName, score, addNumPlayers, SIZE);
	DisplayPlayerData(playerName, score, numPlayers);
	calAVGScore(score, numPlayers);
	AvgBelowPlayerData(playerName, score, numPlayers, avgScore);
	getch();
	return 0;

}

//Data will be inputed in the function below
void InputData(string playerName[], int score[], int addNumPlayers, int SIZE)
{
	
	while (addNumPlayers<SIZE)
	{
		cout << "Enter Player Name (Q to Quit): ";
		cin >> playerName[addNumPlayers];
		if ((playerName == 'Q') || (playerName == 'q'))
		{
			break;
		}

		cout << "Enter score for " << playerName << ": ";
		cin >> score[i];

		//count
		addNumPlayers++;

	}
}

//Overall Data to be displayed
void DisplayPlayerData(string playerName[], int score[], int numPlayers)
{
	cout << "Name" << "     " << "Score" << endl;
	for (int i=0; i<=numPlayers; i++)
	{
		cout << playerName << score << endl;
		//i++??????****????
	}
}

//Overall average score
double calAVGScore(int score[], int numPlayers)
{
	int i;
	double avgScore, totalScore;
	for(int i=0, totalScore = 0; i < numPlayers; i++)
	{
		//accumulate
		totalScore += score[i];
	}
	avgScore = totalScore/numPlayers;
	cout << "Average score is " << avgScore << endl;

	return avgScore;
}

//Individuals below avg score to be displayed
void AvgBelowPlayerData(string playerName[], int score[], int numPlayers, avgScore)
{
	cout << "Players who scored below average" << endl;
	cout << "Name" << "     " << "Score" << endl;
	for (int i=0; i <numPlayers; i++)
	{
		if (score[i] < avgScore)
		cout << playerName[i] << score[i] endl;
	}
}

Recommended Answers

All 7 Replies

What are the messages that the compiler is telling you? Learning how to interpret them is an important skill. Start with the first error. If you can't figure out what it means, post it with the line number.

string playerName[SIZE];
int score[SIZE];

You also should look up vectors.
The above both incurs an unnecessary limitation on the number of objects you can have and in most cases, it just creates lots of instances that are never actually used.

string playerName[SIZE];
int score[SIZE];

You also should look up vectors.
The above both incurs an unnecessary limitation on the number of objects you can have and in most cases, it just creates lots of instances that are never actually used.

He/she might be restricted by the assignment to arrays. A lot of instructors still teach it that way.

What are the messages that the compiler is telling you? Learning how to interpret them is an important skill. Start with the first error. If you can't figure out what it means, post it with the line number.

Errors below before running program:

3 IntelliSense: expected a ';' c:\video game player program\video game player program\video game player.cpp 89 37 Video Game Player Program

1 IntelliSense: identifier "avgScore" is undefined c:\video game player program\video game player program\video game player.cpp 82 75 Video Game Player Program

2 IntelliSense: identifier "avgScore" is undefined c:\video game player program\video game player program\video game player.cpp 88 18 Video Game Player Program

Errors after running program:

Error 4 error C2040: '==' : 'std::string []' differs in levels of indirection from 'int' c:\video game player program\video game player program\video game player.cpp 40 1 Video Game Player Program
Error 6 error C2040: '==' : 'std::string []' differs in levels of indirection from 'int' c:\video game player program\video game player program\video game player.cpp 40 1 Video Game Player Program
Error 8 error C2061: syntax error : identifier 'avgScore' c:\video game player program\video game player program\video game player.cpp 82 1 Video Game Player Program
Error 1 error C2065: 'addNumPlayers' : undeclared identifier c:video game player program\video game player program\video game player.cpp 23 1 Video Game Player Program
Error 9 error C2065: 'avgScore' : undeclared identifier c:\video game player program\video game player program\video game player.cpp 88 1 Video Game Player Program
Error 7 error C2065: 'i' : undeclared identifier c:\video game player program\video game player program\video game player.cpp 46 1 Video Game Player Program
Error 10 error C2146: syntax error : missing ';' before identifier 'endl' c:\video game player program\video game player program\video game player.cpp 89 1 Video Game Player Program

and some repetitive ones...

There are a bunch of undeclared variables here. Look at line 28. Where is addNumPlayers declared? It appears out of nowhere. Look at line 12 and at line 28. Notice anything amiss? (you may have fixed that one because it doesn't appear on your current error list)

PlayerNames is an array of strings. You can't compare an array of strings to just one character on line 45.

In calAvgScore, avgScore comes out of nowhere. It still needs to be declared locally in that function.

On 51, i doesn't exist there (you probably had a loop and you took it out).

Still have no idea how to fix the std::string problems, it would be nice to actually understand the fundamentals behind it.
Current Problems:
[IMG]http://i54.tinypic.com/21mi2ps.png[/IMG]
Current Code:

/* Developer: DaniwebOS
Date Written: January 6, 2011
Purpose: Video Game Player Program
*/
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;

//All Prototypes
void InputaData(string[], int[], int, int);
void DisplayPlayerData(string[], int[], int);
double calAVGScore(int[], int);
void AvgBelowPlayerData(string[], int[], int, double);

//Main Function
int main()
{
	//Local Variable used
	const int SIZE = 100;
	int numPlayers = 0;
	double avgScore;
	
	//---
	string playerName[SIZE];
	int score[SIZE];
	int addNumPlayers;
	InputData(playerName, score, addNumPlayers, SIZE);
	DisplayPlayerData(playerName, score, numPlayers);
	calAVGScore(score, numPlayers);
	AvgBelowPlayerData(playerName, score, numPlayers, avgScore);
	getch();
	return 0;

}

//Data will be inputed in the function below
void InputData(string playerName[], int score[], int addNumPlayers, int SIZE)
{
	int i;
	while (addNumPlayers<SIZE)
	{
		cout << "Enter Player Name (Q to Quit): ";
		cin >> playerName[addNumPlayers];
		if ((playerName == 'Q') || (playerName == 'q'))
		{
			break;
		}

		cout << "Enter score for " << playerName << ": ";
		cin >> score[i];

		//count
		addNumPlayers++;

	}
}

//Overall Data to be displayed
void DisplayPlayerData(string playerName[], int score[], int numPlayers)
{
	cout << "Name" << "     " << "Score" << endl;
	for (int i=0; i<=numPlayers; i++)
	{
		cout << playerName << score << endl;
		//i++??????****????
	}
}

//Overall average score
double calAVGScore(int score[], int numPlayers)
{
	int i;
	double avgScore, totalScore;
	for(int i=0, totalScore = 0; i < numPlayers; i++)
	{
		//accumulate
		totalScore += score[i];
	}
	avgScore = totalScore/numPlayers;
	cout << "Average score is " << avgScore << endl;

	return avgScore;
}

//Individuals below avg score to be displayed
void AvgBelowPlayerData(string playerName[], int score[], int numPlayers, double avgScore)
{
	cout << "Players who scored below average" << endl;
	cout << "Name" << "     " << "Score" << endl;
	for (int i=0; i <numPlayers; i++)
	{
		if (score[i] < avgScore)
		cout << playerName[i] << score[i] << endl;
	}
}
void InputData([B]string playerName[][/B], int score[], int addNumPlayers, int SIZE)
{
    int i;
    while (addNumPlayers<SIZE)
    {
	cout << "Enter Player Name (Q to Quit): ";
	cin >> [B]playerName[addNumPlayers][/B];
	if (([B]playerName == 'Q'[/B]) || (playerName == 'q'))
	{
		break;
	}

You're passing in playerName, which is an array of strings. The playerName variable points to the address of the first string in that array. On line 7 you are respecting this, and writing the string of the addPlayer-th element of playerName[] .
Then on line 8, you are asking the computer to compare the value of the pointer to the first string in the array to the character 'Q'.

The compiler is rightly balking. In order to get the first character of the addPlayer-th string, you need to access playerName[addPlayer][0] which is one character. The first index gives you the entry in the array and the second gives you the character. You could also do something like std::string temp = playerName[addPlayer]; and then access temp[0].

Of course, the above approach will fail with a player name "Quisenberry." So you may want to compare playerName[addPlayer] with "Q" (notice the double quotes).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.