Guessing game: how to quit the game?

This is a discussion on Guessing game: how to quit the game? within the C Programming forums, part of the General Programming Boards category; Hello Everyone, I am writing a guessing game using for loop but did not know how to quite the game ...

  1. #1
    hzr
    hzr is offline
    Registered User
    Join Date
    Dec 2008
    Posts
    2

    Guessing game: how to quit the game?

    Hello Everyone,
    I am writing a guessing game using for loop but did not know how to quite the game at any stage that I want. This is an example of my for loop:

    ...............................................
    case 1:
    askquestion_1( guesses, "\nAttempt %d: Is your animal a dog? ", dog );
    break;
    case 2:
    askquestion_2( guesses, "\nAttempt %d: Is your animal a mouse? ", mouse );
    break;
    .........................................

    How can i quiet after the first break. Can anyone help?


    Thanks.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,470
    use a flag and check it in the loop condition
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I suppose questions are used in a loop. So provide a means to exit that loop at any iteration.

    From the looks of the snippet it also seems that you are hard-coding things that should be handled by loops and arrays.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    hzr
    hzr is offline
    Registered User
    Join Date
    Dec 2008
    Posts
    2
    Could you please give me an example.

    what do you mean by: use a flag and check it in the loop condition


    Thank you.

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,470
    Code:
    int bFlag = 1;
    int index;
    for(index = 0; bFlag && index <10 ; index++)
    {
       if(index == 5)
          bFlag = 0;
    }
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Code:
    int user_wants_to_continue = 1;
    do
    {
        guessed = ask_question();
        if (user_wants_to_abort) user_wants_to_continue = 0;
    } while (!guessed && user_wants_to_continue);
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 04:48 PM
  2. Need book to program game into multiplayer...
    By edomingox in forum Game Programming
    Replies: 3
    Last Post: 10-02-2008, 09:26 AM
  3. Game Designer vs Game Programmer
    By the dead tree in forum Game Programming
    Replies: 8
    Last Post: 04-28-2005, 09:17 PM
  4. number guessing game, no idea where to start
    By karin in forum C Programming
    Replies: 9
    Last Post: 03-18-2004, 08:49 PM
  5. Number guessing game
    By rmathus in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2004, 01:11 PM

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