c++ Structures export data for specific name, country, last name

That is the structure that I created:

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 <string>
    #include <fstream>
    using namespace std;
    
    
    struct Students
    {
    	char first_name[10];
    	char last_name[10];
    	char country[20];
    
    
    };
    int main()
    {
    	Students array;
    	int n, i;
    	cin >> n;
    
    	for (i = 0; i < n; i++)
    	{
    		cout << "Name:";
    		cin >> array.first_name;
    		cout << "Last Name:";
    		cin >> array.last_name;
    		cout << "Country:";
    		cin >> array.country;
    
    	}
    
    	for (i = 0; i < n; i++)
    	{
    		cout << array.first_name << " ";
    		cout << array.last_name << " ";
    		cout << array.country << " ";
    
    
    	}
    	system("pause");
    
    
    }

And I have to write code that once I enter John (for example) displays all information about him: last name, country. And when I enter country to export: first name, last name. Maybe I don't explain it properly. Because my english is bad. Maybe that's the reason that i can't find specific information or similar examples.

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
Ouput example:
n=2
Name:John
Last Name: Doe
Country: England
 
Name:Pete
Last Name: Donaldson
Country: USA

Name:John
Last Name: Peterson
Country: England
 

 
And that's the part that i can't do:
 
/Info about student/
Enter Name for check:
John
 
and here the output must be:
Name:John
Last Name: Doe
Country: England

Name:John
Last Name: Peterson
Country: England
 
another check: 
if I enter Pete:
Name:Pete
Last Name: Donaldson
Country: USA


The same think for country, when if I enter England:
Name:John
Last Name: Doe
Country: England

Name:John
Last Name: Peterson
Country: England
Last edited on
You have defined the Student structure, but you didn't declare an array of Students; therefore, your structure will only hold one student's information (the last one you enter.)

You need to declare an array of Students:

1
2
3
4
5
6
7
8
9

int main( int argc, char** argv )
    {
    Students array[ 10 ];

    }
        /*    main()    */

You have defined the Student structure, but you didn't declare an array of Students; therefore, your structure will only hold one student's information (the last one you enter.)

So is this okay?
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
#include <iostream>
#include <string>
#include <fstream>
using namespace std;


struct Students
{
	char first_name[10];
	char last_name[10];
	char country[20];


};
int main()
{
	Students array[10];
	int n, i;
	cin >> n;

	for (i = 0; i < n; i++)
	{
		cout << "Name:";
		cin >> array[i].first_name;
		cout << "Last Name:";
		cin >> array[i].last_name;
		cout << "Country:";
		cin >> array[i].country;

	}

	for (i = 0; i < n; i++)
	{
		cout << array[i].first_name << " ";
		cout << array[i].last_name << " ";
		cout << array[i].country << " ";


	}
	system("pause");


}
It should be OK. Doesn't it work?
Topic archived. No new replies allowed.