Results 1 to 7 of 7
  1. #1
    AGWStge5rya$@%'s Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    Behind you
    Posts
    630
    Reputation
    33
    Thanks
    242
    My Mood
    Amused

    Return To Top of Program ? [Solved]

    So, in my code, if you enter something you're not supposed to, I wanted it to go back to the top, and repeat it the process until you choose one of the allowed choices.
    Code:
    #include <iostream>
    
    
    
    
    
    using namespace std;
    
    
    
    {
    
    
        string gender;
        cout << "\nBoy or Girl\n";
        cin >> gender;
        if(gender == "boy")
        {
            gender = "Boy";
        }
        cout << "You are a ";
        cout << gender;
        cout << "\n";
        if(gender == "Boy")
        {
            #include "Boy.h"
        }
        else if(gender == "Girl")
        {
            #include "Girl.h"
        }
        if(gender != "Boy","Girl")
        {
            cout << "Please, pick Boy or Girl!";
    
    
    
    
    
        }
    
    }

  2. #2
    turdsammiches's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    105
    Reputation
    60
    Thanks
    14
    My Mood
    Twisted
    i'm no c++ expert but here is my take on your program... i also made it return to the top of the main function if it does not equal boy or girl by putting the whole thing inside a loop.

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    
    {
        string gender;
        while(1)
        {
         cout << "Boy or Girl?\n";
         cin >> gender;
        
         if(gender == "boy")
         {
          gender = "Boy";
          cout << "\nYou are a " << gender << endl << endl;
          #include "Boy.h"
          cout << "Press [ENTER] to exit...";
          cin.ignore();
          cin.get();
          break;
         }
         
         if(gender == "girl")
         {
          gender = "Girl";
          cout << "You are a " << gender << endl;
          #include "Girl.h"
          cout << "Press [ENTER] to exit...";
          cin.ignore();
          cin.get();
          break;
         }
         
         else if (gender != "Boy" | gender != "Girl")
         {
             cout << "Please, pick Boy or girl!\n\n";
         }
        
        }
        return 0;
    }

  3. #3
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    You can put this:

    Code:
     string gender;
        while(1)
        {
         cout << "Boy or Girl?\n";
         cin >> gender;
        
         if(gender == "boy")
         {
          gender = "Boy";
          cout << "\nYou are a " << gender << endl << endl;
          #include "Boy.h"
          cout << "Press [ENTER] to exit...";
          cin.ignore();
          cin.get();
          break;
         }
         
         if(gender == "girl")
         {
          gender = "Girl";
          cout << "You are a " << gender << endl;
          #include "Girl.h"
          cout << "Press [ENTER] to exit...";
          cin.ignore();
          cin.get();
          break;
         }
         
         else if (gender != "Boy" | gender != "Girl")
         {
             cout << "Please, pick Boy or girl!\n\n";
         }
        
        }
    Make that a function, then from your main function call that function.

  4. #4
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    wowow, calm down

    The guy doesn't even know what a Loop is (neither knows what a function is), and yet you tell him to use an infinite loop (thats never good for someone who is learning, well, never is but w/e)? ... Why?

    Also, if he doesn't know what a loop is.. I doubt that he will know what a function is, so.. telling him to call a function ain't a good solution.
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

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

    Hassan (12-13-2011)

  6. #5
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    ^ Nig spoke D:

    If you are going to spoon-feed him, at least give some explanation.

  7. The Following User Says Thank You to Hassan For This Useful Post:

    'Bruno (12-13-2011)

  8. #6
    AGWStge5rya$@%'s Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    Behind you
    Posts
    630
    Reputation
    33
    Thanks
    242
    My Mood
    Amused
    /Request close

    I just made it a While loop. :P
    string gender = "";
    while( gender.compare( "Boy" ) != 0 && gender.compare( "Girl" ) != 0)
    {
    cout << endl << "Boy or Girl?";
    cin >> gender;

  9. #7
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Alright.
    /Closed on Request.

Similar Threads

  1. [Help] Associating file extension with program? [solved]
    By Bombsaway707 in forum Visual Basic Programming
    Replies: 7
    Last Post: 03-21-2011, 07:41 PM
  2. [Help]FTP Program[Solved]
    By Web-Designer in forum Visual Basic Programming
    Replies: 4
    Last Post: 01-24-2011, 06:25 PM
  3. you need a DLL to load a program..?[Solved]
    By o0OpurezO0o in forum Visual Basic Programming
    Replies: 7
    Last Post: 01-02-2011, 05:06 PM
  4. [Help]How to start another program?[Solved]
    By Web-Designer in forum Visual Basic Programming
    Replies: 11
    Last Post: 09-04-2010, 11:13 PM
  5. need hack or program[SOLVED]
    By conker52 in forum CrossFire Help
    Replies: 3
    Last Post: 08-10-2010, 05:04 AM