That is the structure that I created:
#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");
}
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
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
another check:
if I enter Pete:
Name:Pete
Last Name: Donaldson
Country: USA
I should be able to make unlimited checks.
I tryed to make it like this:
for (i = 0; i < n; i++)
char name_for_check[10];
cin >> name_for_check;
for (i = 0; i < n; i++)
{
if (strcmp(array[i].first_name, name_for_check) == 0)
{
cout << array[i].first_name << " ";
cout << array[i].last_name << " ";
cout << array[i].country << " ";
}
}
}
But how to do so that I can make an unlimited number of requests for name_for_check.
I mean that i can check name more than one time.