quote:Originally posted by kentown
NO one knows the reason? or everbody here just think it's too easy?
Well, I have my doubts as to how much you can learn from someone else's half-finished, almost-but-not-quite-working homework. But here goes:
When you get user input with cin, the program waits for a user to type stuff in and press the Enter key. The contents of the input buffer include a C-language "newline" at the end of the input.
When you use cin.getline(x,30), a maximum of 29 characters are read from the buffer. If fewer than 29 characters were entered by the user, the input buffer is now empty. Then the next cin>> or getline() will wait for more user input.
When you use cin>>data.age, the numeric value is read in and the scanning of the input stops when the first non-numeric character is encountered.That means that the newline is left in the input buffer, so that the next cin>> or cin.getline() sees the newline, and thinks that's the end of that line, so it doesn't actually wait for the user to type anything new.
I suggest it might be better to use getline() to get the integer values as well as the character data, then use atoi() or something to convert the age and IQ to ints. I have seen programs that use cin.ignore() to get rid of extra characters in the input buffer.
Note that there are at least two other bugs in the program, so that even after you fix the cin stuff, it still needs some work. If you can't see what the problems are, I suggest you find a better example, or find a book with good examples to start with.