Thread: Need help with goto in c++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    oh for that you would use a loop eg.
    Code:
    int input = 0;
    while(input==0)
    {
        cout<<"hey input still equals 0";
        cout<<"What do you want input to be?";
        cin>>input;
    }
    Woop?

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    24

    Question

    I don`t think thats what i mean, but here`s my code:
    Code:
    #include <iostream.h>
    int main()
    {
      int input;
      cout<<"This game simulates a rich life."<<endl;
    1 cout<<"Input menu function"<<endl;
      cout<<"1: Spend money."<<endl;
      cout<<"2: Play a video game."<<endl;
      cout<<"3: Drive around in a car"<<endl;
      cout<<"4: Climb Mount Everest"<<endl;
      cout<<"5: Fly around in a helicopter"<<endl;
      cout<<"6: Kill yourself"<<endl;
      cin>>input;
    3
      if (input==1)
      {
        cout<<"You buy a helicopter, a building, and a private island."<<endl;
        goto 1;
      }
      else if (input==2)
      {
        cout<<"You turn on your Zcube and play for half an hour."<<endl;
        goto 1;
      }
      else if (input==3)
      {
        cout<<"You drive around in your $900,000,000.95 limo."<<endl;
        goto 1;
      }
      else if (input==4)
      {
        int action;
        cout<<"You climb Mount everest. Now what?"<<endl;
    2   cout<<"1: Shout:'I`m the king of the world!!!'"<<endl;
        cout<<"2: Go back down"<<endl;
        cin>>action;
        if (action==1)
        {
          cout<<"I`m the king of the world!!!"<<endl;
          goto 2;
        }
        else if (action==2)
        {
          goto 1;
        }
        else
        {
          cout<<"Please input menu functions only"<<endl;
          goto 2;
        }
      }
      else if (input==5)
      {
        cout<<"You fly around in your helicopter."<<endl;
        goto 1;
      }
      else if (input==6)
      {
        goto 3;
        return 0;
      }
    }
    Do you know what i`m doing wrong here?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  2. goto command
    By jhwebster1 in forum C Programming
    Replies: 3
    Last Post: 02-21-2006, 12:32 PM
  3. Does goto have a glitch or...?
    By Blackroot in forum C++ Programming
    Replies: 9
    Last Post: 02-18-2006, 10:40 AM
  4. helpppp
    By The Brain in forum C Programming
    Replies: 1
    Last Post: 07-27-2005, 07:05 PM
  5. Need some help with a basic tic tac toe game
    By darkshadow in forum C Programming
    Replies: 1
    Last Post: 05-12-2002, 04:21 PM