#include <iostream>
#include <string>
#include <fstream>
usingnamespace 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.
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
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.)