My program displays the details of 2 students. name id address module code and module marks. my program works well but the problem is when i enter the details of the 2nd student i am not able to enter the name as if it skip this first part and go directly to id here are my codes:
#ifndef STUDENT_H
#define STUDENT_H
class student
{
public:
void enterDetails();
void enterModule();
void displayDetails();
float computeCPA();
private:
char name[100];
char studID[100];
char address[100];
char module[100];
float marks[100];
float CPA[100];
int M[20][2];
};
#include <cstdlib>
#include <iostream>
using namespace std;
#include "student.h"
void student::enterDetails()
{
cout<<"enter name: ";
cin.getline(name,100,'\n');
cout<<"enter id: ";
cin.getline(studID,100,'\n');
cout<<"enter address of student: ";
cin.getline(address,100,'\n');
cin.ignore();
}
void student::enterModule()
{
cin.ignore();
}
void student::displayDetails()
{
cout<<"Name: "<<name<<endl;
cout<<"ID: "<<studID<<endl;
cout<<"Address: "<<address<<endl;
cin.ignore();
}
#include <cstdlib>
#include <iostream>
#include "student.h"
using namespace std;
int main(int argc,char *argv[])
{
int x;
string M[20][2];
int row,col;
const int MAXSTUDENT = 2;
student s1[MAXSTUDENT];
cout<<"Processing details of Student"<<endl;
for (int i=0; i<MAXSTUDENT; i++){
s1[i].enterDetails();
cout<<"Enter number of modules:" ;
cin>> x;
for(row=0;row<x;row++)
{
cout << " Enter module code and corresponding module marks :" ,(row+1);
for(col=0;col<2;col++)
cin >> M[row][col];
}
}
cout<<"Displaying details of Student"<<endl;
for (int i=0; i<MAXSTUDENT; i++){
s1[i].displayDetails();
for (row=0; row<x; row++)
{
for(col=0;col<2;col++)
cout << "\t" <<M[row][col];
cout<< endl;
}
}
return EXIT_SUCCESS;
}