I've been learning C++ for about a year now, and it's the first lower-level language I've learned. Anyway, here's my problem:
I have a program with aloop in it. Inside this loop is aCode:while()integer. It looks something like this:Code:char
Now, for some reason, when the user enters two words with a space in between them in the "question" entry, the program ignores the loop. So then I tried this:Code:#include <iostream.h> #include <string.h> int main() { int x = 0; while (x == 0) { char question[80]; cin >> question; cout << "\nWould you like to play again? (Y/N): "; char yorn[10]; char y[] = "y"; char n[] = "n"; cin >> yorn; x = strcmp(yorn, y); } return 0; }
ect...Code:#include <iostream.h> #include <string.h> int main() { int x = 0; while (x == 0) { char question[80]; cin.get(question, 79);
That works, but then when you run the program again, the program ignores the. What is causing this? is there any way to clear the data out ofCode:cin.get(question, 79);Code:char buffer?



LinkBack URL
About LinkBacks


