An array, within an array?

Say I want to quickly store 3 personality traits of 3 different people into an array quickly, then display them in a format such as:
Johny:
Favorite pizza: Pepperoni
Favorite animal: Dog
Favorite Color: Blue

(so four inputs/person)

But I don't want to enter 3 names, then 3 favorite pizzas, then 3 favorite animals.
I want to input all 4 variables per single person at once...

so when collecting the data, the user will be asked for name, then pizza, then animal, then color.
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
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

void inputs(int);

string name[3];
int one;


int main()
{



	for (one=0;one<=2;one++)
	{
		inputs(one);
	}
	for (one=0;one<=2;one++)
	{
		cout << name[one] << endl;
	}
		

			return 0;

}

void inputs(int i)
{
	cout << "Enter person(" << i + 1 << ") name" << endl;
	cin >> name[one];
}

This is what I have but I don't know how I would interrupt the name array to allow for the other 3 array inputs... help??

I believe I should use a different method rather than "for" statement to call attention to getting the input.. but I can't figure out how..

EDIT: again the point is to be able to store and output all data as an array
Last edited on
Use a better data structure, like a struct:

1
2
3
4
5
6
7
struct Person
{
    string name;
    string pizza;
    string animal;
    string color;
};

Then, in main, you can do the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Person person[3];

for (int i = 0; i < 3; i++)
{
    cout << "Enter the name of person " << i + 1 << ": ";
    cin >> person[i].name;
    
    cout << "Enter the favorite pizza of person " << i + 1 << ": ";
    cin >> person[i].pizza;
    
    cout << "Enter the favorite animal of person " << i + 1 << ": ";
    cin >> person[i].animal;
    
    cout << "Enter the favorite color of person " << i + 1 << ": ";
    cin >> person[i].color;
    
    cout << endl;
}


excellent!
Now would there possibly be a way for after each person's data is entered, the console is cleared?
as well as before the data is outputted
system("cls");

found in cstdlib, will clear the Windows command prompt. Its use is discouraged, but for this program, it's fine.
Topic archived. No new replies allowed.