I have this code which works fine but I cant comprehend the meaning of cin.get(ch) in the for loop. I tested the program after removing it and the first input comes fine but as soon as loop runs for the second time, program does not wait for the user to input "name" and skips automatically to "marks".
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
void main ()
{ clrscr();
int marks;
char name[40];
char ch;
ofstream a("STUDENT.txt",ios::app);
char ans='y';
while(ans=='y'|| ans=='Y')
{ cout<<"\nEnter name of student: " ;
cin.getline(name,40);
cout<<"Enter marks of student: ";
cin>>marks;
cout<<"Want to enter more? (y/n)";
cin>>ans;
cin.get(ch);
a<<"\n"<<name<<"\n"<<marks;
}
a.close ();
getch();
}