c++ beginner - input name using struct

This is the description of the practise im doing.
Write a program that reads peoples’ names and ages into an array of type struct.
The names should be stored in a field as a C-style string ( char [] ), and the ages in a field of type int.
The array should allow a maximum of 100 names and ages to be read in, the input being sentinel controlled on the name field (“quit”). When the sentinel is entered there should be no age input.
Pass the array to a function that prints a table of names and ages. Remember to pass both array name and size. Pass the array to a second function that calculates the average age. The function should return the average age, which should be printed in main() as type float.
NOTE: The program should not crash if no data is entered by the user.

I have got the code below, amd im quite confused with working out the sentinal control. i know that there will be while .. something but i feel stuck somehow. but i'm still thinking about it. Hope you could help me this.

The code hasn't finished yet, but i hope it could summarise. 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
 #include<iostream>
#include<conio.h>
#include<stdio.h>
#include<iomanip>
#include<string>
#include<array>
using namespace std;

struct Detail
{
	char name[ 20 ];
	int  age;
};

void printNameAge( Detail [], int );
//------------------------------------------------------------------------------
int main()
{
	const int MAX = 3;
	Detail person[ MAX ];
	char quit;
	float average;


	while ( printNameAge != quit )
	{
		if ( int i = 0, i < MAX )
		{
		cout << endl << "Enter your name: ";
		cin.getline( person[ i ].name, MAX );
		cout << "\nEnter your age: ";
		cin  >> person[ i ].age;
		cout << left << setw( 20 ) << person[ i ].name;
		i++;
		}
	}

	getch();
	return 0;
}
//------------------------------------------------------------------------------
void printNameAge( Detail array[], int size )
{


}
Perhaps:

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

constexpr int MaxName {20};

struct Detail {
	char name[MaxName] {};
	int age {};
};

void printNameAge(const Detail[], int);

int main() {
	constexpr int MAX {3};
	constexpr const char* quit {"quit"};
	Detail person[MAX];
	//float average {};

	int noEnt {};

	for (; noEnt < MAX; ++noEnt) {
			std::cout << "\nEnter your name: ";
			std::cin.getline(person[noEnt].name, MaxName);

			if (std::strcmp(person[noEnt].name, quit) == 0)
				break;

			std::cout << "\nEnter your age: ";
			std::cin >> person[noEnt].age;
			std::cin.ignore();
	}

	printNameAge(person, noEnt);
}

void printNameAge(const Detail array[], int size)
{
	for (int e = 0; e < size; ++e)
		std::cout << array[e].name << "  " << array[e].age << '\n';

	std::cout << '\n';
}


Just needs the average function now - and output formatting...
for the average. does it average for the number of person or 100?
Why would you count people-who-don't-exist in your average?
ah, its a political survey!
Topic archived. No new replies allowed.