Does it ever end

This is a discussion on Does it ever end within the C++ Programming forums, part of the General Programming Boards category; please explain wats wrong Code: #include <iostream> using namespace std; int main(); { int number=9; int guess; cout << "What ...

  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
    21,935
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,935
    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,935
    No you use:
    guess < number && guess > 0
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,935
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 08:35 AM
  2. Modify to make Doubly Linked List
    By Dampecram in forum C Programming
    Replies: 10
    Last Post: 11-03-2008, 06:25 PM
  3. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 06: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

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