Thread: New to C++, writing first script, need help finding bug

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    1

    New to C++, writing first script, need help finding bug

    First off, please don't hate on me I know I'm a total noob! I keep getting an error when I try to compile this and I can't seem to find out why. I'm reviewing the book I purchased to help me, but I still can't find out whats going wrong. I know its something small and dumb.. Can ANYONE help

    If you could please point out what needs to be corrected and why, it would be extremely helpful to me. Thank you so much in advance.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int secret_number, guess, count;
        
        cout << "Let's play a guessing game!"  << endl << endl;
        cout << "I'll pick a number from 0 to 9, inclusive." << endl;
        cout << "Good luck!" << endl  << endl;
    
    secret_number = rand() % 10;
    count = 0;
    do { 
         if (count)
            cout << "Sorry, that's not it!" << endl;
            cout << "enter your guess: ";
            cin >> guess;
    { while ( guess != secret_number ) && ( ++count <= 9 ) );
    
    
    if ( guess == secret_number )
    {
         cout << "You got it in " << count << "guesses!" < endl;
         cout << "Good work!" << endl;
    }
    else
    {
        cout << "Sorry, you used up all your guesses!" << endl;
        cout << "The secret number was: " << secret_number << endl;
        cout << "Better luck next time!" << endl;
    }
    
        system("PAUSE");
        return EXIT_SUCCESS;
    }

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Those fiddly bits aren't matching up are they.

    Soma

  3. #3
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Those fiddly bits aren't matching up are they.
    I'd say the "curly" bits, to be more specific.
    Consider this post signed

  4. #4
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    It would be extremely helpful to everyone trying to help you if you post the error your getting.

  5. #5
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I'd say the "curly" bits, to be more specific.
    Fair enough...

    Soma

  6. #6
    Registered User
    Join Date
    Sep 2010
    Posts
    15

    Thumbs up

    I can see that 3 errors from here. Check the curly braces in the while. Also, one of your cout is lack of one more "<". I'm sure that like me, some others can see the errors. But is up to you to find them. Please, check this out and tell me what you tried to fix and how you did it and maybe I will be more specific.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to implementate a registration script
    By TJa in forum C++ Programming
    Replies: 0
    Last Post: 10-28-2005, 02:33 AM
  2. Passing arguments to script.....
    By suwie in forum C Programming
    Replies: 5
    Last Post: 09-25-2004, 11:10 PM
  3. Recource Script Bug in VC++
    By Xzyx987X in forum Windows Programming
    Replies: 1
    Last Post: 04-24-2004, 09:19 PM
  4. Need help finding bug
    By Guti14 in forum C++ Programming
    Replies: 2
    Last Post: 10-05-2003, 02:21 AM
  5. Linux script
    By deltabird in forum Linux Programming
    Replies: 1
    Last Post: 05-02-2003, 03:31 PM