I'm new here and fairly new to c++. Not sure if this forum is exclusivly for students because I am not one, just learning it for fun. I read the "read me" on flushing the input stream but it seemed rather complicated. What's happening is if the correct color is chosen the first time everything works great but if your choose wrong and are asked to choose again it somehow cycles through the loop as if it recieved input even though it hasn't. Is there a simple way to flush the input or is there something I can do to clean up my code so I don't have that problem in the first place?
int main()
{
string sentance;
string black="color";
string color="none";
do
{
cout<<"Enter a sentance using your favorite color\n\n";
getline(cin,sentance);
if(sentance.find("black")!=string::npos)
color="black";
if (color=="none")
{
cout<<"I don't like that color, can you call it a different one?\n";
cin>>color;
}
cout<<"Color is:\t"<<color<<"\n";
color="none";
}
while (black=="color");
return 0;
}