Thread: total newbie question

  1. #1
    Unregistered
    Guest

    Unhappy total newbie question

    I just started learning c++ last night, so please dont get too mad at my ignorence or if this is a previously asked question:

    Using the bloodshed dev c++ compiler, whenever i attempt to create a dos program that involves a user imputing a variable to the program (i.e.

    #include <iostream.h>

    int main()

    {

    int thisisanumber;

    cout<<"Please enter a number:";

    cin>>thisisanumber;

    cout<<"You entered: "<<thisisanumber;

    return 0;

    }

    ) the program always closes after the imput is entered, even when i place cin.get(); before return 0;. How can i make the output window remain and get it to display the appropreate responce? Thanks in advance for any help.

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    267
    *cries* READ THE FAQ!

  3. #3
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Hmm, I totaly understand d00b. The FAQ is your friend

  4. #4
    Unregistered
    Guest
    sry about that..

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    (Folks, let's remember that this is an out-of-the-egg novice...)

    Unregistered,

    Please register. It let's everyone know that you are, at least, that interested in participating out here.

    Next, (as you've, no doubt, put together), please read the FAQ. Think of it as "survival training", if nothing else.

    Now, near the top of the page (right-hand side), you'll see six "buttons". Click on "search" and see what you can come up with concerning your problem. Hint: your question has been done to death...resurrection...and death again. (Not a shot at you, but it might explain the other responses you received. )

    Learn about code tags. This knowledge will make your life much better out here. There are a lot of very mean members on this board - not really, but it's amazing as to how people conduct themselves behind the "shield of anonymity" that this gizmo affords us!

    Lurk and read. You'll discover who the members are whose code, knowledge and style you'll want to emulate. (I'd name a few, but that's my opinion. Form your own. (Prelude is a woman, by the way.) )

    Personal note, and I'm getting the asbestos underwear (non-friable) ready , please, proofread your posts. Post intelligently, both in grammar and spelling. This is a discussion board, not a "chat room". Intelligent questions elicit intelligent responses...most of the time.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  6. #6
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    when you post at the top it should say, "if your posting a question did you read the FAQs" (wiht a link to the faq board) then unregis and newbs will chekc out the faqs first
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    Klinerr1,

    I'm beginning to think that you're "sandbagging".

    (Most folks don't know to place a comma preceding the quote. )

    Did you post simply to irritate me?

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  8. #8
    Registered User
    Join Date
    Jun 2002
    Posts
    267
    skipper, didn't you know? Klinerr is the king of typos! He needs hooked on phonics!

  9. #9
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    d00b,

    He's the king as far as I'm concerned!

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  10. #10
    Registered User
    Join Date
    Aug 2002
    Posts
    10

    still cant get it right..

    Ok, I'm registered now,

    I'm still having the same trouble after using the getch() and kbhit() functions, and even tried get(). I realise that you all probably get this question alot, but i searched the boards and could not find an answer. Could someone possiply post or link some code for me to learn from, that can respond to imput when the user presses enter (plz keep the codes simple if possible.)? Hopefully that doesnt come across as too pushy on my part, just a bit frustrated that its taking me so long to figure this out :/

  11. #11
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    spoude,

    For registering, you get one freebie:

    Code:
    #include <iostream>
    #include <conio.h>  // for getch
    // using namespace std; (commented out for illustration)
    
    int main()
    {
    int thisisanumber;
    // int this_is_a_number;  // preferred notation
    
    // std::cout and std::cin used in place of global 'using namespace std;'
    std::cout <<"Please enter a number:";
    std::cin >> thisisanumber;
    
    // cout << "Please enter a number: "; // can be used if 'using namespace std;'
                                          //   is made global (see third line of code)
    // cin >> this_is_a_number;
    
    std::cout << "You entered: " << thisisanumber;
    
    getch();  // non-standard; do not use std::getch();
    return 0;
    }
    This code compiles and runs on Borland C++Builder 4 & 5, as well as MSVC++6.0.

    I'm not familiar with the dev C++ compiler, but have read numerous threads from folks who've experienced one problem, or another, with it. (Good compiler, from what I "hear", but not without its eccentricities. Perhaps others might share their trials and tribulations with you.)

    Hope this gets you going.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  12. #12
    Registered User
    Join Date
    Aug 2002
    Posts
    10
    That helped me alot, thank you. It works on the beta version for dev c++ 5, but not on 4 just for everyones's information (I'm not sure why though).

  13. #13
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    spoude,

    Glad to help.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  14. #14
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    If you are like me and prefer using standard C++ files and functions whenever possible, even if it means you have to push an extra key or two (heaven forbid), do this:
    Code:
    #include <iostream.h> //or iostream if your compiler is newer
    
    //using namespace std;  if you need to use namespaces.  Not the best approach to doing so, but it works and is standard.
    
    int main()
    {
      cout << "hello world" << endl;
      char ch;
      cout << "to close program press any key and then the enter key" << endl; 
      cin >> ch;
      return 0;
    }

  15. #15
    Registered User
    Join Date
    Aug 2002
    Posts
    10
    One more question , how can I find out if a function is stardard or not?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with day of the week program
    By Punkakitty in forum C++ Programming
    Replies: 10
    Last Post: 01-14-2009, 06:55 PM
  2. Replies: 8
    Last Post: 11-03-2008, 09:48 PM
  3. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  4. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  5. Newbie question about registries/files
    By SirDavidGuy in forum C++ Programming
    Replies: 1
    Last Post: 02-20-2002, 09:58 PM