Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Thanks again. Everything with the questions works fine now. The only odd problem

ID: 3625244 • Letter: T

Question

Thanks again. Everything with the questions works fine now. The only odd problem is that it doesnt work with the answers now. If the answer is one word, then it is fine, but more than one word and it goes nuts. Just to try, alter the "questions.txt" and "answers.txt" with sentences and see what I'm talking about. Everything else works fine though. I got one more question after I post this one!

Here is the function for this question.

void ask(string q,string a,int &knows,bool& correct,string p[] )
{
string ans;
char c;
int prev=knows;
cout << " "<< endl;
cout << " "<< endl;
cout<<q<<endl;
cout << " "<< endl;
cout << " "<< endl;
cout<<p[0]<<" enter 0, "<<p[1]<<" enter 1 to indicate you know the answer: ";
cin>>c;
knows=c-'0';
while(knows<0||knows>1)
{cin>>c;
knows=c-'0';
}

cout << " "<< endl;
cout << " "<< endl;
cout<<"OK "<<p[knows]<<" what is the answer: ";
cin>>ans;
if(a.compare(ans)==0)
{correct=true;
cout<<"That is correct"<< endl;
}
else
{correct=false;
cout<<"That is incorrect"<< endl;
knows=prev;
}
for(int i=0;i<400000000;i++);
}

Explanation / Answer

please rate - thanks

same problem as previously cin should be getline and must flush the input buffer between getting the character and the string

void ask(string q,string a,int &knows,bool& correct,string p[] )
{
string ans;
char c;
int prev=knows;
cout<<q<<endl<<p[0]<<" enter 0, "<<p[1]<<" enter 1 to indicate you know the answer: ";
cin>>c;
knows=c-'0';
while(knows<0||knows>1)
    {cin>>c;
    knows=c-'0';
     }
while ((getchar()) != ' ');
cout<<"OK "<<p[knows]<<" what is the answer: ";
getline(cin,ans);
if(a.compare(ans)==0)
        {correct=true;
        cout<<"That is correct ";
        }
else
        {correct=false;
        cout<<"That is incorrect ";
        knows=prev;
        }
for(int i=0;i<400000000;i++);      
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote