Infinite Loop!!!

This is a discussion on Infinite Loop!!! within the C++ Programming forums, part of the General Programming Boards category; Code: void guessinggame() { cout<<"\n\n--------------------------------------------------\n\n"; cout<<"GUESSING GAME\n\n"; cout<<"You will have 4 guess to guess a number between 0 and 30.\nGOOD ...

  1. #1
    Programmer Frantic-'s Avatar
    Join Date
    Dec 2004
    Posts
    114

    SOLVED:Infinite Loop!!!

    Code:
     void guessinggame()
          {
               cout<<"\n\n--------------------------------------------------\n\n";
               cout<<"GUESSING GAME\n\n";
               cout<<"You will have 4 guess to guess a number between 0 and 30.\nGOOD LUCK!\n\n";
               guessinggame();
               }
               
              
          //*****************************************
         //*                                       *
         //*         GUESSING GAME CONT            *
         //*                                       *
         //*****************************************
              
               
               
          void guessinggamecont()
          {
               int input;
               int choice;
               
               for (int x=0; x<5; x++){
                   cout<<"Please enter your guess:";
                   cin>>input;
                   if (input == 17){
                             x=6;
                             cout<<"You are correct, thank you for playing the guesing game.\nYou will now be taken back to the Control Center.";
                             cin.get();
                             desktop;
                             }
                   else {
                        x++;
                        }
                             }
                             cout<<"Sorry, but you were unable to guess the secret number.\nWould you like to play again?";
                             cout<<"\n\n1.)Yes\n2.)No\n\nSelection:";
                             cin>>choice;
                             switch (choice){
                                    case 1:
                                        guessinggamecont();
                                        break;
                                    case 2:
                                         desktop();
                                         break;
                                    default: 
                                         cout<<"INTERNAL ERROR [696E76616C696420656E74727900]";
                                         cin.get();
                                         cin.get();
                                         return; 
                                             
           }
           }
    i found me error

    Code:
     void guessinggame()
          {
               cout<<"\n\n--------------------------------------------------\n\n";
               cout<<"GUESSING GAME\n\n";
               cout<<"You will have 4 guess to guess a number between 0 and 30.\nGOOD LUCK!\n\n";
               guessinggame();
               }

    it kept calling upon it self, it should have been:

    Code:
     void guessinggame()
          {
               cout<<"\n\n--------------------------------------------------\n\n";
               cout<<"GUESSING GAME\n\n";
               cout<<"You will have 4 guess to guess a number between 0 and 30.\nGOOD LUCK!\n\n";
               guessinggamecont();
               }
    Last edited by Frantic-; 12-13-2004 at 06:32 PM.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I don't see one off the top of my head but I do see a logic error:
    Code:
    for (int x=0; x<5; x++){
    Code:
    else {x++;
    On a bad guess you'll increment twice

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >MOD PLEASE DELETE, I FIXED MY PROBLEM!
    No! This is an open, public forum. You don't delete your question when it's solved, you leave it so that others can learn from it and discuss the solutions that were suggested. I'm sorry, I don't give out red rep often, but this is just bad form. I strongly disapprove.
    My best code is written with the delete key.

  4. #4
    Programmer Frantic-'s Avatar
    Join Date
    Dec 2004
    Posts
    114
    Quote Originally Posted by Prelude
    >MOD PLEASE DELETE, I FIXED MY PROBLEM!
    No! This is an open, public forum. You don't delete your question when it's solved, you leave it so that others can learn from it and discuss the solutions that were suggested. I'm sorry, I don't give out red rep often, but this is just bad form. I strongly disapprove.
    its back up. sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-15-2009, 12:24 AM
  2. Cosine fucntion and infinite loop.
    By youareafever in forum C Programming
    Replies: 2
    Last Post: 11-07-2008, 04:45 AM
  3. Infinite Loop with GetAsyncKeyState
    By guitarist809 in forum Windows Programming
    Replies: 1
    Last Post: 04-18-2008, 01:09 PM
  4. Switch statement = infinite loop
    By Lucid003 in forum C++ Programming
    Replies: 10
    Last Post: 10-10-2005, 01:46 AM
  5. stays in loop, but it's not an infinite loop (C++)
    By Berticus in forum C++ Programming
    Replies: 8
    Last Post: 07-19-2005, 12:17 PM

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