I am new to programming and working on a basic student management system. The system first asks the user for data input. 6 things; the id, name, university, department, semester and gpa. The data input is working perfectly. After the data input is complete, a menu appears with three options. one is to create a new student profile. In that case, when the user enters the name of the student, the program is terminated abruptly. I've used cin.ignore every single place where it makes sense but the same problem occurs. Any help would be appreciated. Thank you. Code is below. NOTE: I was not allowed to use structures and/or vectors.
#include<iostream>
#include<string>
using namespace std;
int main()
{
cout<<"------------------------------------- Welcome to student management system! ----------------------------------------------"<<endl;
cout<<"------------------------------------------------DATA INPUT----------------------------------------------"<<endl;
cout<<"Enter the number of students you want to enroll: ";
int size;
int n=0;
int counter=0;
cin>>size;
int *student_ids=new int[size];
int *semester=new int[size];
float *cgpa=new float[size];
string *names=new string[size];
string *uni=new string[size];
string *dept=new string[size];
int *ptr_id,*ptr_semester;
string *ptr_names,*ptr_uni,*ptr_dept;
float *ptr_cgpa;
cout<<"Enter their ids: "<<endl;
ptr_id=student_ids;
for(int i=0;i<size;i++)
{
cin>>*ptr_id;
ptr_id++;
}
ptr_names=names;
cout<<"Enter their names: "<<endl;
cin.ignore();
for(int i=0;i<size;i++)
{
getline(cin,*ptr_names);
ptr_names++;
}
ptr_uni=uni;
cout<<"Enter their Universities: "<<endl;
for(int i=0;i<size;i++)
{
getline(cin,*ptr_uni);
ptr_uni++;
}
ptr_dept=dept;
cout<<"Enter their departments: "<<endl;
for(int i=0;i<size;i++)
{
getline(cin,*ptr_dept);
ptr_dept++;
}
ptr_semester=semester;
cout<<"Enter their semester: "<<endl;
for(int i=0;i<size;i++)
{
cin>>*ptr_semester;
ptr_semester++;
}
ptr_cgpa=cgpa;
cout<<"Enter the GPA: "<<endl;
for(int i=0;i<size;i++)
{
cin>>*ptr_cgpa;
ptr_cgpa++;
}
cout<<"-----------------------------------------------DATA INPUT COMPLETE----------------------------------------------------------- "<<endl;
int choice;
char again='y';
while(again=='y'||again=='Y')
{
cout<<"Press 1 to Create a Student Profile"<<endl;
cout<<"Press 2 to Search a Student"<<endl;
cout<<"Press 3 to Delete a Student record"<<endl;
cin>>choice;
switch(choice)
{
case 1: //CREATING STUDENT PROFILE
cout<<"Enter the number of profiles you want to create: ";
cin>>n;
cout<<"Enter ID(s): ";
for(int i=size;i<size+n;i++)
{
cin>>*ptr_id;
ptr_id++;
}
cout<<student_ids[1];
cout<<student_ids[0];
cout<<"Enter name(s): ";
cin.ignore();
for(int i=size;i<size+n;i++)
{
getline(cin,*ptr_names);
cin.ignore();
ptr_names++;
}
cout<<names[1]<<endl;
cout<<"Enter University: ";
for(int i=size;i<size+n;i++)
{
getline(cin,*ptr_uni);
ptr_uni++;
}
cout<<"Enter Department(s): ";
for(int i=size;i<size+n;i++)
{
getline(cin,*ptr_dept);
ptr_dept++;
}
cout<<dept[2]<<endl;
cout<<"Enter semester(s): ";
for(int i=size;i<size+n;i++)
{
cin>>*ptr_semester;
ptr_semester++;
}
cout<<"Enter CGPA: ";
for(int i=size;i<size+n;i++)
{
cin>>*ptr_cgpa;
ptr_cgpa++;
}
cout<<"------------------------------------------------SUCCESS-------------------------------------------------------------";
cout<<endl;
break;
case 2: //SEARCHING
int searching_method;
cout<<"Press 1 to search by ID."<<endl;
cout<<"Press 2 to list all students."<<endl;
cin>>searching_method;
switch(searching_method)
{
case 1: //SEARCHING BY ID
cout<<"Enter the student ID: ";
int search;
cin>>search;
for(int i=0;i<size+n;i++)
{
if(student_ids[i]==search)
{
counter++;
cout<<"Name: "<<names[i]<<endl;
cout<<"University: "<<uni[i]<<endl;
cout<<"Department: "<<dept[i]<<endl;
cout<<"Semester: "<<semester[i]<<endl;
cout<<"CGPA: "<<cgpa[i]<<endl;
break;
}
}
if(counter==0)
{
cout<<"No student found!"<<endl;
}
break;
case 2: //LIST OF ALL STUDENTS
for(int i=0;i<size+n;i++)
{
cout<<"Student ID: "<<student_ids[i]<<endl;
cout<<"Name: "<<names[i]<<endl;
cout<<"University: "<<uni[i]<<endl;
cout<<"Department: "<<dept[i]<<endl;
cout<<"Semester: "<<semester[i]<<endl;
cout<<"CGPA: "<<cgpa[i]<<endl;
cout<<endl;
cout<<endl;
}
break;
}
//case 3: //DELETEING A STUDENT ID
}
}
system("pause");
return 0;
}