Thread: Items....

  1. #1
    Unregistered
    Guest

    Question Items....

    I want to link my main item to a 3 other ones at dif places lets call the others 1, 2 and 3.

    How would i go about doing that?

  2. #2
    Unregistered
    Guest
    I would try to help you, but I do not know what you are talking about.

  3. #3
    Unregistered
    Guest

    hmm

    Well you have ur first *main* part of the program it does stuff I give the user options to hit 1, 2 or 3 and when they hit them I want it to go to one of the less important parts.

  4. #4
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Go different places, as in call different functions?

    Code:
    #include <iostream>
      using namespace std;
      void function1();
      void function2();
      void function3();
    int main()
    {
      cout << "Enter a number (1-3)" << endl;
      int iNumber;
      cin >> iNumber;
      if(iNumber == 1)
        function1();
      else if(iNumber == 2)
        function2();
      else if(iNumber == 3)
        function3();
      else
        cout << "You did not enter a valid number" << endl;
      return 0;
    }
    
    void function1()
    {
      cout << "You hit 1" << endl;
    }
    
    void function2()
    {
      cout << "You hit 2" << endl;
    }
    
    void function3()
    {
      cout << "You hit 3" << endl;
    }
    Is that what you are talking about?

  5. #5
    Unregistered
    Guest

    sorta

    like...... you have all the code for main k.... then it says like hit 1 to turn left 2 to go straight or 3 to jump up and down


    there is already lots of code so i want to go to a new page for each so i would????????

  6. #6
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Turn what left? You are not being very clear...

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    4
    plz elaborate on what you are talking about so we can help you.
    tell us what you are trying to do and what part of the program is giving you trouble. maybe show us some code.

  8. #8
    Unregistered
    Guest

    ok....

    it says:


    cout << "You can:\n1 = Turn left\n2 = Turn right\n3 = Walk straight.\n";
    cin number;
    if (number == 1)


    then I want it if they type 1 they go to like a dif. script page to make it less crowded and

    if (number == 2)

    a dif. one then the other 2.

    and so on

  9. #9
    first of all you cant put cin number;, because you need the overload. Use this instead:
    Code:
    cin>>number;
    now the next thing, all you need to do is make some if statements to see what the user pressed. Then call the appropriate functions to what the user wants to do.

  10. #10
    Unregistered
    Guest
    yeah my cin i did wrong on here but not on the thing...... but guys listen.... I want it so

    what they choose a bunch of dif. things will happen for each not the same for each.

  11. #11
    Registered User
    Join Date
    Mar 2002
    Posts
    27

    functions are the way

    Basically you want to consturct functions. here is how to do it:

    Code:
    #inlcude <iostream.h>
    
    void func1()
    {
         cout<<"alialty alah";
    }
    
    void func2()
    {
         cout<<"bliblty blah";
    }
    
    void func3()
    {
         cout<<"dlidlty dlah";
    }
    
    void main()
    {
            int choice;
            cout<<"Enter 1 to do function 1. enter 2 to do function 2...";
            cin<<choice;
             if(choice==1)
                   func1();
            i f(choice==2)
                   func2();
            if(choice==3)
                   func3();
    }
    When this is run if you enter a 1 it will say "alialty alah"....

    You said something about clearing. do you mean clearing the screen? if so include the stdlib.h library and do this when you want to clear system("CLS");

    The other thing you can do is make a library. you just make functions and stcick them in a header file, and you can call the function just as if it were written at the top of your code.

    Gr3g
    Last edited by Gr3g; 03-29-2002 at 06:05 PM.
    Chance favors the prepared mind.

    Vis. C++ 6.0

  12. #12
    Registered User
    Join Date
    Mar 2002
    Posts
    23
    I would use a case statement since it'll be easier to add in extra features later on and plus its easier to read than 3 if statements.
    Code:
    #include <iostream>
    
    int main()
    {
      int x;
      
      cin >> x;
    
      switch(x)  {
      
      case 1: 
         func1();
         break;
    
      case 2: 
         func2();
         break;
    
      case 3: 
         func3();
         break;
    
      default:
        cout << "not a choice! ";
     }
    }//end main()
    Of course you would have to define func1() and so on like stated before but that is probally the best way to do it.

    -Dennis

  13. #13
    Registered User Sekti's Avatar
    Join Date
    Feb 2002
    Posts
    163

    i think

    he wants to use gotoxy() to move something right when 1 is hit i dont know how to do it but i know thats what you do
    +++
    ++
    + Sekti
    ++
    +++

  14. #14
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Look up the function clrscr(). It'll clear the screen so it looks like a new console window. But, if you need to have a new window it's gonna be more advanced.

  15. #15
    WhiteRider
    Guest

    Lightbulb

    Theres stuff on clearing the screen in the FAQ.

    Also look at the source on this website which has some stuff movement examples that someone put up.

    Also you probably want to put the switch and input into a loop

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Welcome to Cprogramming.com and AI Horizon's Message Board
    By kermi3 in forum General AI Programming
    Replies: 9
    Last Post: 06-04-2009, 01:25 AM
  2. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  3. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  4. Retail Outlet Managment System - the 4th
    By Presidentofusa in forum C Programming
    Replies: 3
    Last Post: 11-10-2007, 10:44 PM
  5. CListView & Appending Items :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 04-28-2002, 11:37 AM