I'm trying to write a structure where i ask to the user how much students he wants to register. Then it ask for the name, code, group and score of the students, and then print the results. When I run it, it goes ok until when it comes to print the results. I tried with just printed the name, but it doesn't work. What's wrong, how I fix it? Thanks
Your 'i' variable does not exist outside of the for loop (nor should it).
You need to loop again to print the data in the array.
1 2 3 4
for (int i = 0; i < n_alumnos; i++)
{
cout<<"Nombre: "<<est[i].nombre<< '\n';
}
Also, cin>>est[i].grupo,5;
The 5 here doesn't do anything. It does not prevent a buffer overflow, which can happen because cin >> char array is not safe.
If you used strings (#include <string>), this would not be an issue.
Hint: You can hit "edit post", highlight your code and then press the <> formatting button. This will not automatically indent your code. That part is up to you.
You can use the "preview" button at the bottom to see how it looks.