Storing three names and their batting averages.

Hello!

I'm working on some C++ homework, and I've hit a little snag. I'm trying to figure out how to store three different user defined names and averages assigned to each one. So far my code asks for input three times, but only outputs the last name and average entered three times. How would I get it to print the three names and averages entered? I'm still figuring out structs and arrays.

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
  #include <iostream>
#include <ctime>

using namespace std;

struct Players
{
	char Name[50];
	double average;
};
void getPlayersAverage(Players *plr);
void printPlayersAverage(Players p);

int main()
{
	Players p, p1;

	for (int i = 0; i < 3; i++)
	{
		getPlayersAverage(&p);
	}
	for (int i = 0; i < 3; i++)
	{
		printPlayersAverage(p);
	}

	system("pause");
}
void getPlayersAverage(Players *plr)
{
	cout << "Enter the player's name: " << endl;
	cin >> plr->Name;

	cout << "Enter the player's average: " << endl;
	cin >> plr->average;
}
void printPlayersAverage(Players p)
{
	cout << p.Name << " Is hitting " << p.average << endl;
}
Make p an array:
1
2
3
4
5
Players p[3];
...
getPlayersAverage(&p[i]);
...
printPlayersAverage(p[i]);
Topic archived. No new replies allowed.