Acá está mi código:
Código PHP:
#include <iostream>
#include <cstdlib>
using namespace std;
class Usuarios {
public:
void registrarUsuarios();
void mostrarUsuario();
char* GetName() { return this->Name; }
private:
char Age[3];
char CellPhone[10];
char Name[40];
char Surname[50];
char Direction[60];
};
int main()
{
int length = 0;
char Name[40];
cout << "How many users do you want to register?: "; cin >> length;
if(length <= 0) {
cout << "\n\nYou have wrote a wrong value." << endl;
cout << "Press any key to continue..." << endl;
system("pause>nul");
return 1;
}
system("cls");
Usuarios usuarios[length];
for(int r = 0 ; r < length ; r++)
usuarios[r].registrarUsuarios();
cout << "Write the name of the user who you wish find: "; cin >> Name;
for(int r = 0; r < length; r++) {
if(Name == usuarios[r].GetName())
usuarios[r].mostrarUsuario();
else if(r == (length - 1))
cout << "The user hasn't been found." << endl;
}
system("pause>nul");
return 0;
}
void Usuarios::registrarUsuarios() {
cout << "Name: "; cin >> this->Name;
cout << "Surname: "; cin >> this->Surname;
cout << "Age: "; cin >> this->Age;
cout << "Direction: "; cin >> this->Direction;
cout << "Cell Phone: "; cin >> this->CellPhone;
cout << "----------------------------------------" << endl;
}
void Usuarios::mostrarUsuario() {
cout << "Name: " << this->Name << endl;
cout << "Surname: " << this->Surname << endl;
cout << "Age: " << this->Age << endl;
cout << "Direction: " << this->Direction << endl;
cout << "Cell Phone: " << this->CellPhone << endl;
}
El problema, creo, que radica acá:
Código PHP:
for(int r = 0; r < length; r++) {
if(Name == usuarios[r].GetName())
usuarios[r].mostrarUsuario();
else if(r == (length - 1))
cout << "The user hasn't been found." << endl;
}