+ 1
[SOLVED] How do I store string answers with "cin"?
I'm trying to make code that .. if I type "yes" something pops up and if i type "no" something pops up. I know how to do to it with number. For example: 1 is yes and 3 is no. Here is my code sorry if it is messy. #include <iostream> #include <string> using namespace std; int main() { int a; // I know this must be string. cout << "Do u want to learn code?\n"; cout << "yes or no?"; <censored the rest : profanity & char-limit> - CipherFox
7 odpowiedzi
+ 6
Jordi de Pelseneer
I understand that programming can be frustrating sometimes, BELIEVE me ... but for future reference, please try to avoid posting profanity to the Q&A.
+ 2
You can do this the easiest way. Just change "int a;" to "string a;" and in your "if" type "if(a == "yes")" and "if(a == "no")" . ( cin works the same way for strings)
+ 1
i did that but i get an error that yes isn't declared
+ 1
oooh i forgot the "" stupid me
+ 1
thanks man it works
+ 1
i dont know c++ but looks similar to java
"yes or no\n" << this is cout theres no reason why its saying yes isnt declared as its inside print method
the only declaration you have is int a; which im assuming is cin a type of scanner.
code looks alright to me
+ 1
thanks i found my problem :)