while loop keeps looping without getting input from user

struct stu_dat //outside main function
int rollno;
char name[45],
float average;

char ans='y'; //inside main function
cout<<"want to enter more data?';

No compilation problem.when executing prompt waits for inputting rollno
but, as soon as i enter a char string it keeps looping displaying the "want to enter more data?".i cant understand what is going on,as there is no compilation problem and runs good till i input the name.
replace cin.get with cin >>. Or if you insist with going with methods from istream, use cin.getline instead
could you please explain why get() function is causing this ?
Because it leaves a trailing newline character in the input stream. See this answer for a fix:

Topic archived. No new replies allowed.