Well since im like 2 days old too c++ and i just learned cin and strings can someone help me i want to know how to make my command prompt answer to a yes or no question heres my source code
Code:#include <iostream> #include <string> using namespace std; int main () { string mystr; cout << "What's your name? "; getline (cin, mystr); cout << "Hello " << mystr << ".\n"; cout << "What's your last name? "; getline (cin, mystr); cout << "So its " << mystr << " ?\n"; cout << "Do you like Aimbots? "; getline (cin, mystr); cout << "Well i havent figured out how to answer to yes or no questions yet im sorry ill get back to you later..\n"; cout << "Its all about that MPGH.net\n"; system ("pause"); return 0; }
please dont flame my post i am 2 days new to c++ so...
This was not my complete source code i have been learning from C++ Basic Tutorial
Last edited by IamArtificial; 07-29-2010 at 12:11 PM.
Light travels faster than sound. That's why most people seem bright until you hear them speak.
VvITylerIvV (08-02-2010)
No one is going to flame you for asking a question. Here is an example to answering a question:
Warning, you will have to type in exactly "Yes" or "No". You can use functions like "tolower()" to force all the characters to lower case so you can check for non case-sensitive inputs.Code:#include <iostream> #include <string> using namespace std; int main() { string input=""; cout<<"Say yes or no\n"; cin>>input; if (input=="Yes") { cout<<"You said Yes\n"; } if (input=="No") { cout<<"You said No\n"; } if (input!="No" && input!="Yes") { cout<<"You didn't say yes or no"; } system("pause"); return 0; }
But anyways, I hope I could help. This compiled in MSVC++ 2008 Express edition.
~lilneo
Thanks it is XD ^.^ heres my finishing thing it was surprisingly easy
Code:#include <iostream> #include <string> using namespace std; int main () { string mystr; cout << "What's your name? "; getline (cin, mystr); cout << "Hello " << mystr << ".\n"; cout << "What's your last name? "; getline (cin, mystr); cout << "So its " << mystr << " ?\n"; cout << "Do you like Aimbots? "; getline (cin, mystr); if (mystr == "no") cout << "Well your gay...\n"; if (mystr == "No" cout << "Well your gay...\n"; if (mystr == "NO") cout << "Well your gay...\n"; if (mystr == "yes") cout << "Its all about that MPGH.net\n"; if (mystr == "Yes") cout << "Its all about that MPGH.net\n"; if (mystr == "YES") cout << "Its all about that MPGH.net\n"; system ("pause"); return 0; }
@Lilneo
all i did was theCode:if (mystr == "no") cout << "message here\n"
Last edited by IamArtificial; 07-29-2010 at 12:25 PM.
I could put a long list of what i want to achieve here on MPGH but who the hell cares?
nice, btw one tip.. instead of having all these if's with same result, you could do:
|| is the same as "OR", you can also use && which is "AND". But yea, keep practicing and follow that site tutorial wellCode:if(xxx = "xxx" || xxx2 = "xxx" || xxx3 = "xxx")
edit: btw, search around the web for some exercises, so you can actually practice.
Light travels faster than sound. That's why most people seem bright until you hear them speak.
look good? i think it does XDCode:#include <iostream> #include <string> using namespace std; int main () { string mystr; cout << "What's your name? "; getline (cin, mystr); cout << "Hello " << mystr << ".\n"; cout << "What's your last name? "; getline (cin, mystr); cout << "So its " << mystr << " ?\n"; cout << "Do you like Aimbots? "; getline (cin, mystr); if (mystr == "no" || mystr == "No" || mystr == "NO" || mystr == "Hell No") cout << "Well then your gay..\n"; if (mystr == "yes" || mystr == "Yes" || mystr == "YES") cout << "MPGH.net is where its at!!\n"; system ("pause"); return 0; }
I could put a long list of what i want to achieve here on MPGH but who the hell cares?
'Bruno (07-29-2010)
I don't know if you've learned functions yet, but you can use this to convert strings to lowercase:
Code:#include <windows.h> #include <iostream> using namespace std; string strToLower(string convertme); //forward declaration so we can put the function behind main int main() { string a = "TLDFLSDF"; a = strToLower(a); //convert the string to lowercase cout<<a.c_str(); //print the string as char array/c style string return 1; } string strToLower(string convertme) { for(int i=0;i<(int)strlen(convertme.c_str()); i++) { convertme[i] = tolower(convertme[i]); } return convertme; }
Ah we-a blaze the fyah, make it bun dem!
'Bruno (07-29-2010),IamArtificial (07-30-2010)
Favourite quotes:
Definition of computing: The use or operation of computers.Code:I don't need easy, I just need possible. ~ Me There are three birds on a fence. Two decide to fly away, how many are left? Three, just because you decide to do something doesn't mean you've done it. ~ Don't know who said this Do not go where the path may lead, go instead where there is no path and leave a trail. ~ Ralph Waldo Emerson
Turning on my computer = computing = programming
LAWLFAIL