parrallel array difficulty

Ok so I'm having a lot of trouble finishing this program.
let me post the abtract so i can explain better.
(From the console: Input a Name and age into 2 parallel arrays until age reaches an assigned sentinel value.

For editing ensure age is between 1 and 110 inclusively. After the information has been input into the 2 parallel arrays, then create a loop that will print out each names and its corresponding age, each on a separate line. I also expect to see headings for each column with a professional look, (columns and headings lined up.) After printing out the list of names and corresponding ages, then skip 2 lines and print out the average age of the list of ages entered. (Average Age = xxx.x with the in alignment with column of ages.) )

what I cant figure out is how to create a sentinel in the for loop without crashing my compiler(DevC++).
Also the teacher never explained to to avg numbers from an array, and this is not in my book either.
i have the array set to 5 by 5 for testing purposes, but its supposed to be an indefinite number, so the array parameters are set by the sentinel ending the input. Also a concept never covered in the text or by the teacher.
Please help.

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

using namespace std;


int main()
{
	string stu_name[5] = {""};
	int stu_age[5] = {0};
	
	string name;
	int age, avgAge;
		


	for (int i = 0; i < 5; i++)
	{
		cout << "Enter in Name: ";
		cin >> name;
		
		cout << "Enter Age: ";
		cin >> age;
		while(age < 1 || age > 110)
		{
			cout << "Invalid age, Enter Age: ";
			cin >> age;
		}
		if(stu_name[i] == "")
			stu_name[i] = name;
		if(stu_age[i] == 0)
			stu_age[i] = age;
	}
	cout << endl;
	cout << "Name" << setw(8) << "Age" << endl;
	cout << endl;
	cout << endl;
	
	for (int i = 0; i <=5; i++)
	{
		cout << setprecision(2) << setw(10) << left <<stu_name[i] << setw(10) << stu_age[i] << endl;	
	}
	

	return 0;
}.
You have to add the following statement in your loop(s);
1
2
if(stu_age[i] == 110)
  break; // This will end the loop 


For average you simply sum the ages and devide them by the number:
1
2
3
avgAge += stu_age[i];
if(stu_age[i] == 110)
  avgAge /= i + 1;
Topic archived. No new replies allowed.