Play Again feature problem

This is a discussion on Play Again feature problem within the C++ Programming forums, part of the General Programming Boards category; I want to add Do you want to play again? (y/n): question to my program.. I wrote the code to ...

  1. #1
    Akilla
    Guest

    Play Again feature problem

    I want to add

    Do you want to play again? (y/n):

    question to my program..

    I wrote the code to take the input, etc..

    the only problem is... if he says yes, i have
    to restart my whole program ... how do i do that ?

    when i said main(), obviously, it says that i can't call
    main from the function...

    how is this accomplished ?

    www.akilla.tk

  2. #2
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    use a loop

  3. #3
    Akilla
    Guest

    ??

    Elaborate please ...


    by the way, i already have while inside a while inside a while inside a while.... :-) think if i add one more while, doesn't it screw it up ?

    moreover, i am using seperate functions to do seperate things in the program... this playagain feature is also used as a seperate function.. so how do i do it now ?

    www.akilla.tk

  4. #4
    Akilla
    Guest

    and..

    "screw it up" in the sense ... doesn't it slow it down ?

    www.akilla.tk

  5. #5
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Code:
    int main()
    {
      char caReplay;
    
      do
      {
        function (...);
        caReplay = function_n(...);
      }while(caReplay != 'n');
    
      return 0;
    }
    Break your program up into functions or else methods actually if you are using c++.

    Game cGame;
    ...(loop)
    cGame.Sequence(...);
    caReplay = cGame.FinalSequence(...);
    ...

    Do something like this, but make it better.

  6. #6
    Akilla
    Guest

    can I use a goto ?

    Can I use a goto from one function to go to another place in another function ??


    [code]
    void askquestion()
    {
    char answer;
    cout << play again (y/n);
    cin >> answer;

    blah blah blah,
    on so and so, goto gamestart
    }

    main()
    {
    gamestart:
    blah blah blah
    blah blah blah
    blah blah blah
    }

  7. #7
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    goto..

    Wouldn't recommend it. While it is valid code, it doesn't make it very easy to debug should a problem arise.

    A while loop is your best bet. Generally most games are written with a main loop that executes as long as the game is running, (as long as the user doesn't end the game). Within this loop your game logic is executed.
    Last edited by foniks munkee; 07-21-2002 at 09:23 PM.
    "Queen and huntress, chaste and fair,
    Now the sun is laid to sleep,
    Seated in thy silver chair,
    State in wonted manner keep."

  8. #8
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    Code:
    #include <iostream>
    using namespace std; 
    
    string again;
    
    int main()
    {
                                             again = "yes";
                                        while (again == "y" || again =="yes") {
    
    //code + crap here
    
          	cout << "Would you like to play again? (y/n)" << endl;
            			cin >> again;
                 if(again == "n" || again == "no")
    }
    cin.get();
    return 0;
    }
    something like that is what i think you need
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM
  5. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 06:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21