I'm creating a c++ program to enter student information in a structure in c++. So when I enter the students it's getting the data and redirects me to the main menu. When I select an option to see that that data I have entered it's not displaying but when I call that same data to be displayed soon after entering it, it's displaying. My code is below:
//My structure to get students
struct Students{
string RegNumber;
string StudentFullName;
string Program;
string Lvl;
};
//User selects from this menu
MainMenu(){
menu:
cout <<"Select From The Menu\n";
cout <<"1. Add Student Details\n 2. View Student details\n";
//User selected from the menu option function
int UserInputOption;
cin >> UserInputOption;
//validating User Input
if(UserInputOption < 2){
int NumberOfStudents;
Students student[NumberOfStudents];
//Switch statements to check user input
switch(UserInputOption){
case 1:
//Enter Number of students to add to the system
cout << "Enter The Number of Students You Want To Enter\n";
cin >> NumberOfStudents;
//Adding new students to the system
cout << "*********************************************\n";
cout << "Enrolling Students to the system\n";
cout << "*********************************************\n";
//loop for entering student details
for(int i=0; i < NumberOfStudents; i++){
cout <<"Enter Student Reg Number: ";
cin >> student[i].RegNumber;
cout <<"Enter Student Full Name: ";
cin >> student[i].StudentFullName;
cout <<"Enter Student Program: ";
cin >> student[i].Program;
cout <<"Enter Student Level: ";
cin >> student[i].Lvl;
cout << "\n";
}
cout << "\n*********************************************\n";
cout << "Students Enrolled To The System\n";
cout << "*********************************************\n";
//After Entering the student details the system should go back to the main menu
goto menu;
break;
case 2:
//Displaying all students of in the system
for(int i=0; i < 1; i++){
cout << student[i].RegNumber;
cout << student[i].StudentFullName;
cout << student[i].Program;
cout << student[i].Lvl;
}
break;
}
}else{
cout <<"Invalid Input"<<endl;
}
}
int main()
{
//Calling methods to the main method
MainMenu();
return 0;
}