Thread: Help?

Results 1 to 14 of 14
  1. #1
    IamArtificial's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    90
    Reputation
    10
    Thanks
    10
    My Mood
    Bored

    Help?

    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.

  2. #2
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  3. The Following User Says Thank You to 'Bruno For This Useful Post:

    VvITylerIvV (08-02-2010)

  4. #3
    IamArtificial's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    90
    Reputation
    10
    Thanks
    10
    My Mood
    Bored
    Quote Originally Posted by Brinuz View Post
    hmmmm thanks ive been learning from there :P

  5. #4
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by IamArtificial View Post
    hmmmm thanks ive been learning from there :P
    good then thats your next step. good luck
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  6. #5
    lilneo's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Canada
    Posts
    217
    Reputation
    8
    Thanks
    28
    No one is going to flame you for asking a question. Here is an example to answering a question:
    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;
    }
    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.

    But anyways, I hope I could help. This compiled in MSVC++ 2008 Express edition.

    ~lilneo

  7. #6
    IamArtificial's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    90
    Reputation
    10
    Thanks
    10
    My Mood
    Bored
    Quote Originally Posted by Brinuz View Post
    good then thats your next step. good luck
    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 the
    Code:
    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?

  8. #7
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by IamArtificial View Post
    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;
    }
    nice, btw one tip.. instead of having all these if's with same result, you could do:

    Code:
    if(xxx = "xxx" || xxx2 = "xxx" || xxx3 = "xxx")
    || is the same as "OR", you can also use && which is "AND". But yea, keep practicing and follow that site tutorial well

    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.

  9. #8
    IamArtificial's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    90
    Reputation
    10
    Thanks
    10
    My Mood
    Bored
    Quote Originally Posted by Brinuz View Post
    nice, btw one tip.. instead of having all these if's with same result, you could do:

    Code:
    if(xxx = "xxx" || xxx2 = "xxx" || xxx3 = "xxx")
    || is the same as "OR", you can also use && which is "AND". But yea, keep practicing and follow that site tutorial well

    edit: btw, search around the web for some exercises, so you can actually practice.
    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" || 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;
    }
    look good? i think it does XD
    I could put a long list of what i want to achieve here on MPGH but who the hell cares?

  10. The Following User Says Thank You to IamArtificial For This Useful Post:

    'Bruno (07-29-2010)

  11. #9
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by IamArtificial View Post
    look good? i think it does XD
    way better xP
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  12. #10
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    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!

  13. The Following 2 Users Say Thank You to Hell_Demon For This Useful Post:

    'Bruno (07-29-2010),IamArtificial (07-30-2010)

  14. #11
    IamArtificial's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    90
    Reputation
    10
    Thanks
    10
    My Mood
    Bored
    Quote Originally Posted by Hell_Demon View Post
    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;
    }

    Its wierd you posted this i just got to functions last night but i stopped XD
    so i am learning functions right now xP
    I could put a long list of what i want to achieve here on MPGH but who the hell cares?

  15. #12
    VvITylerIvV's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    The streets
    Posts
    668
    Reputation
    5
    Thanks
    61
    My Mood
    In Love
    Quote Originally Posted by lilneo View Post
    No one is going to flame you for asking a question. Here is an example to answering a question:
    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;
    }
    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.

    But anyways, I hope I could help. This compiled in MSVC++ 2008 Express edition.

    ~lilneo



    Or you could use
    Code:
    if (input!="No" || "no" && input!="Yes" || "yes")
    Not sure if this will work properly, but it allows for yes, Yes, no and No questions if it does work.
    Favourite quotes:

    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
    Quote Originally Posted by VirtualSia View Post
    You both have a very weird and awkward view on Computer science.
    Computer science is about computing, which is programming.
    Definition of computing: The use or operation of computers.
    Turning on my computer = computing = programming
    LAWLFAIL

  16. #13
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by VvITylerIvV View Post
    Or you could use
    Code:
    if (input!="No" || "no" && input!="Yes" || "yes")
    Not sure if this will work properly, but it allows for yes, Yes, no and No questions if it does work.
    No that wont work.

    This should:

    [php]
    if (input != "no" || input != "No" && input != "Yes" || input != "yes")
    [/php]

    anyway i always hate this kind of ifs, but yea..
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  17. #14
    Auxilium's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,518
    Reputation
    445
    Thanks
    609
    My Mood
    Happy
    Quote Originally Posted by lilneo View Post
    No one is going to flame you for asking a question. Here is an example to answering a question:
    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;
    }
    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.

    But anyways, I hope I could help. This compiled in MSVC++ 2008 Express edition.

    ~lilneo
    [php]string input="";[/php]
    You dont need to initialize it
    [php]string input;[/php]
    is just fine

Similar Threads

  1. [Help Request] Combat arms Vid help
    By djw111 in forum Combat Arms Help
    Replies: 4
    Last Post: 12-24-2011, 05:06 PM
  2. [Help Request] AFK Bot [help]
    By fet in forum Combat Arms Help
    Replies: 7
    Last Post: 04-28-2011, 03:17 AM
  3. [Help Request] Injector Admin help
    By asdfgas in forum Combat Arms Help
    Replies: 4
    Last Post: 04-27-2011, 06:12 PM
  4. [Help Request] Ajuda / Help
    By - Battery' in forum Combat Arms BR Coding Help
    Replies: 3
    Last Post: 04-22-2011, 07:15 PM
  5. [Help Request] Help my!
    By Windowns7 in forum Combat Arms BR Coding Help
    Replies: 2
    Last Post: 04-18-2011, 01:41 PM