Hello all, I'm really sorry if this as been posted already. I looked around and couldn't find an answer. Here's the whole code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
usingnamespace std;
int main () {
string answer;
cout<<"Would you like to see if test program works?"<<endl;
cin >>answer;
if(answer == 'y'){
cout<<"Well fine, then, be that way."<<endl;
}
}
Whenever I run it, I keep getting the same error:
error: no match for'operator==' in 'answer == 'y''
I looked and looked and looked, but I failed to see how to resolve this issue. What am I missing?
You used answer as string so, answer == 'y' will definitely wrong because 'y' is for character though you used string as your data type you need to use answer =="y"..
Oh my God! So simple! Worked, thank you friend. I set the identifier to char instead. If I were to use string anyhow, you say I would use quotations instead of apostrophes?