Thread: Help!

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    27

    Help!

    Problem Solved!
    Last edited by Mrzach3590; 07-25-2006 at 10:56 PM.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    What does "won't run correctly in the compiler" mean? Compiler crashes? Gives errors? Program runs but exits right away?

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    27
    It runs and it lets me enter the 2 #'s but when i hit enter compiler exits out and wont add

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    27
    It runs and it lets me enter the 2 #'s but when i hit enter compiler exits out and wont add

  5. #5
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Add 2 std::cin.get() to the end of your code. You didn't tell it to wait for you to see the result.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    This is a common problem. Check the FAQ about waiting for a keypress. One simple solution is to add std::cin.ignore() after the call to std::cin >>, and then add std::cin.get() before the return 0. The ignore ignores the newline from when you hit <enter> after inputting the two numbers, the get() waits for you to hit <enter> again so it can get another character.

  7. #7
    Registered User
    Join Date
    Jul 2006
    Posts
    27
    Hah ok it works thanks a ton I danced in my chair rofl. Now i can move past page 6!

  8. #8
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    arrgggh, stop asking this question! seriously it's been asked and answered so many times on this forum that I propose an instant ban on anyone posting it.

    READ THE <insert diety here>-DAMNED FAQ
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  9. #9
    Registered User
    Join Date
    Jul 2006
    Posts
    27
    ok, anyone know how to write a program in for and while to print the numbers from 10 down to 0?

  10. #10
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Yes. Yes I do.

  11. #11
    Registered User
    Join Date
    Jul 2006
    Posts
    27
    Could you help me write one lol, the book i got has it for a practice question but really didnt go over it, or atleast i dont think it did.

  12. #12
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Ok, first off, for and while are loops. They can execute a sequence of code a set amount of times, hence the name loop.

    The format of the for loop is as follows -

    Code:
    for ( something = initial condition; something less (etc) than final condition; change the value of something )
    {
      // Do something here.
    }
    the something is normally an integer for regular purposes, but it can be anything. the while can be like this

    Code:
    while ( something is less/greater/not equal etc to something else )
    {
      // Do something here
    }
    If you set the conditions of those loops accordingly, and have a std::cout<< to output the value of the number being changed by the loop, you should get the program to work.

  13. #13
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    >>ok, anyone know how to write a program in for and while to print the numbers from 10 down to 0?

    Isn't it a book exercise?
    You passed page 6 when you posted 6 posts. You want to keep the number of your post equal to page number of the book you are reading?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  14. #14
    Registered User
    Join Date
    Jul 2006
    Posts
    27
    Thanks twomers! I successfully wrote a while loop!

  15. #15
    Registered User
    Join Date
    Jul 2006
    Posts
    27
    New question up top, im a hardcore noob to programming rofl.

Popular pages Recent additions subscribe to a feed