bool simpleQuestion::checkAnswer(string guess) const
for (int i=0;i<qAnswer.length();i++)
this is my code and what im trying to accomplish here is making the comparison of the two strings (qAnswer & guess) case insensitive. I know i need to loop through each character of each string and for each character i can use toupper and every char in each string will become uppercase and therefore case insensitive. However, im not sure how to go about this; if anyone could show me a technique used to loop through each character of the string and how to use toupper that would be great!
bool simpleQuestion::checkAnswer( std::string guess ) const
for( char& c : guess ) c = std::toupper(c) ; // convert guess to upper case
std::string temp = qAnswer ; // make a copy of qAnswer
for( char& c : temp ) c = std::toupper(c) ; // convert it to upper case
return guess == temp ; // compare for equality
> this function is constant so within the function i cant actually alter the calling object.
> is this correct?