Thread: Does it ever end

  1. #1
    I'll take you down! polonyman's Avatar
    Join Date
    Sep 2004
    Posts
    50

    Exclamation Does it ever end

    please explain wats wrong
    Code:
    #include <iostream>
    using namespace std;
    
    int main();
    {
        
        int number=9;
        int guess;
        
        cout << "What day is my birthday on (Between 1 and 31)" << endl;
        cout << "Enter your guess, please?";
        cin >> guess
        if(guess == number)
        {
            cout << "Incredible, you are correct!" << endl;
        }
        else if(guess < number && > 0)
        {
            cout << "Your guess is too low" << endl;
        }
        else if(guess > number && < 32)
        {
            cout << "Your guess was too high" << endl;
        }
        else
        {
            cout << "You either entered a number below 1, above 31 or a decimal. Incorrect, please try again" << endl;
        }
        return 0;
    }
    plz

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Semi-colon on line 4 after main() that shouldnt be there.
    Missing semi-colon on line 12.
    Improperly formed conditional on lines 17 and 21.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    I'll take you down! polonyman's Avatar
    Join Date
    Sep 2004
    Posts
    50
    wat is wrong with conditions on 17 and 21?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Consider:
    guess < number && > 0

    So we have:
    guess < number
    which is ok.

    Then we have:
    > 0
    So what is compared to to see if it is greater than 0?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    I'll take you down! polonyman's Avatar
    Join Date
    Sep 2004
    Posts
    50
    so wat, do i use == instead?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No you use:
    guess < number && guess > 0
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    I'll take you down! polonyman's Avatar
    Join Date
    Sep 2004
    Posts
    50
    thank you very much!

  8. #8
    I'll take you down! polonyman's Avatar
    Join Date
    Sep 2004
    Posts
    50

    more

    fixed wat u said but still wont work
    Code:
    #include <iostream>
    using namespace std;
    
    int main();
        
        int number=9;
        int guess;
        
        cout << "What day is my birthday on (Between 1 and 31)";    
        cout << "Enter your guess, please?";    
        cin >> guess;  
        {
        if(guess == number)
        {
            cout << "Incredible, you are correct!" << endl;
        }
        else if(guess < number && guess > 0)
        {
            cout << "Your guess is too low" << endl;
        }
        else if(guess > number && guess < 32)
        {
            cout << "Your guess was too high" << endl;
        }
        else
        {
            cout << "You either entered a number below 1, above 31 or a decimal. Incorrect, please try again" << endl;
        }
        return 0;
    }

  9. #9
    I'll take you down! polonyman's Avatar
    Join Date
    Sep 2004
    Posts
    50
    decided to add this but no improvement although i knew it wouldn't fix it, just the app wont close
    Code:
    #include <iostream>
    #include <limits>
    using namespace std;
    
    int main();
        
        int number=9;
        int guess;
        
        cout << "What day is my birthday on (Between 1 and 31)";    
        cout << "Enter your guess, please?";    
        cin >> guess;  
        {
        if(guess == number)
        {
            cout << "Incredible, you are correct!" << endl;
        }
        else if(guess < number && guess > 0)
        {
            cout << "Your guess is too low" << endl;
        }
        else if(guess > number && guess < 32)
        {
            cout << "Your guess was too high" << endl;
        }
        else
        {
            cout << "You either entered a number below 1, above 31 or a decimal. Incorrect, please try again" << endl;
        }
        
        cin.ignore();
        cin.get();
        return 0;
    }
    plz

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Here's the code, assuming that you arent quite running it from command line and so need the cin.ignore() at the end.
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int number = 9;
        int guess;
    
        cout << "What day is my birthday on (Between 1 and 31)" << endl;
        cout << "Enter your guess, please?";
        cin >> guess;
        if (guess == number)
        {
            cout << "Incredible, you are correct!" << endl;
        }
        else if (guess < number && guess > 0)
        {
            cout << "Your guess is too low" << endl;
        }
        else if (guess > number && guess < 32)
        {
            cout << "Your guess was too high" << endl;
        }
        else
        {
            cout << "You either entered a number below 1, above 31 or a decimal. Incorrect, please try again" << endl;
        }
        cin.ignore(2);
        return 0;
    }
    If you have a problem, describe it.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    You put:

    int main();

    It should be:

    int main()
    {

    That's a problem.

  12. #12
    I'll take you down! polonyman's Avatar
    Join Date
    Sep 2004
    Posts
    50

    thankz

    thankz so much , i never realised that before

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Modify to make Doubly Linked List
    By Dampecram in forum C Programming
    Replies: 10
    Last Post: 11-03-2008, 07:25 PM
  3. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 07:47 PM
  4. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM
  5. Next Question...
    By Azmeos in forum C++ Programming
    Replies: 3
    Last Post: 06-06-2003, 02:40 PM