pointer-to-object type?

Wrote my code and got a squiggly line, and not sure what it means. I've underlined where the error is referenced in the code. It's line 37.

Error Message: "Expression must have pointer-to-object type."


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
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

//Global Declarations: Functions
string pName;

int main()
{
	string name[100]; //Array for name entries
	double score[100]; //Array for the scores
	double avgScr = 0; //score average
	int totalPlayers = 0; //total number of players
	
	displayData(name[100], score[100]);
}

void displayData(string &name, double &score)
{
	int x = 0;
	while (x <= 99)
	{
		cout << "Player name (Q to quit): "; //name
		cin >> name[x];

		//Quit Options 
		switch (name[x]) 
		{
		case 'Q': break;
		case 'q': break;
		default: x = x;
		}

		cout << "\nPlayer score: "; //score
		cin >> score[x];
		x++;
	}

}
Last edited on
You are passing single values instead of entire arrays. Also, index 100 is out of bounds - the indexes of your arrays are from 0 to 99.

Look up how to pass arrays to functions.
Last edited on
Thanks for pointing that out, I thought that because arrays start at 0 that x would have to be 99, and I thought we had to declare the total number of spaces in the beginning.
Last edited on
So, I made a bit of progress, but not much. I figured out how to carry over the array, but now I have more errors. Underlined the errors.

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
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

//main function
int main()
{
	string name[100]; //Array for name entries
	double score[100] = { 0 }; //Array for the scores
	double avgScr = 0; //score average
	int x = 0;
	int totalPlayers = 0; //total number of players
	
	displayData(name[], score[]); //call to function:: Errors here are about expecting an expression.
}

//Input and Display name and score
void displayData(string name[], double score[], int x) 
{
	for (int x = 0; x <= 99; x++)
	{
		cout << "Player name (Q to quit): "; //name
		cin >> name[x];

		//Quit Options 
		switch (name[x]) //Error here must have integral or enum type
		{
		case 'Q': break; //Errors here have char type instead of string
		case 'q': break;
		default: 
			cout << "\nPlayer Score: ";
			cin >> score[x];
		}
	}

}
Last edited on
On line 16 you're still not passing the arrays correctly - remove the [] completely.

On line 28, you cannot switch on strings. Use if,else-if statements instead.
Last edited on
Darn it. Thank you for your help. But, on line 20, I still keep the brackets, correct?
Yes, just be aware though that as a parameter or return type, double score[] will degrade to double *score. It's a weird carry-over from C, but it does what you want.
Last edited on
Cool. Thank you for your help and explanations!
Topic archived. No new replies allowed.