This is a small fragment of a system for a hospital, where the user must register by entering the information requested. I can't figure it out because it throws me errors. What I want to achieve is that the data entered by the user is saved in the arrays of the struct.
#include <iostream>
#include <stdlib.h>
#include <string>
#include <map>
#include <conio.h>
using namespace std;
#define MAX 5555556
//STRUCTS
struct paciente{
string nombrepac[MAX];
string apellido[MAX];
int dni;
int telefono;
}datos[MAX];
int main(){
for (int i = 0; i < MAX; i++){
while(getchar()!='\n');
cout << "Ingrese su nombre: " << endl; cin >> datos[i].nombrepac;
cout << "Ingrese su apellido: " << endl; cin >> datos[i].apellido;
cout << "Ingrese su DNI: " << endl; cin >> datos[i].dni;
cout << "Ingrese su numero de telefono: " << endl; cin >> datos[i].telefono;
}
cout << "Presione ENTER para regresar al menu anterior. " << endl; getch(); system("cls");
}
Thanks a lot!!
In your structure, what you are doing is that they have a maximum length with the variable
MAX
for the first and last name.Now the problem would be in the
cin
, where you are storing in the members of thestruct
without their length[MAX]
, you would have to do the same thing in the member that has this length:Now, I understand that what you want to do is register the data of several patients to later list them. Improving your code a bit, it would look like this:
Output: