Please Help!!!!!!

This is a discussion on Please Help!!!!!! within the C++ Programming forums, part of the General Programming Boards category; İ have juxt started to learn C++. and i tried to write a basic main fuction but when i run ...

  1. #1
    Whats gonna happen now! himanch's Avatar
    Join Date
    Feb 2005
    Location
    Armenia
    Posts
    26

    Please Help!!!!!!

    İ have juxt started to learn C++. and i tried to write a basic main fuction but when i run it the program suddenly closes!!

    Can someone tell me the reason!!!
    Here is the code........

    [CODE]include <iostream>

    using namespace std;

    int main()
    {
    int number;
    {
    cout<<"Enter Any Number: ";
    cin>> number;
    cout<<"The number you entered"<< number <<"\n";
    cout<<"The mult. of your number with two"<< number * 2 <<"\n";
    }
    cin.get();
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    You have a newline left in the buffer after the first cin, which gets eaten by the cin.get(), thus your console closes. You need to add an ignore() or equivalent to eat the newline.
    Code:
    include <iostream>
    
    using namespace std;
    
    int main()
    {
       int number;
    
       cout<<"Enter Any Number: ";
       cin>> number;
       cin.ignore(std::numeric_limits < int >::max(), '\n');
       cout<<"The number you entered"<< number <<"\n";
       cout<<"The mult. of your number with two"<< number * 2 <<"\n";
    
       cin.get();
    }

  3. #3
    Whats gonna happen now! himanch's Avatar
    Join Date
    Feb 2005
    Location
    Armenia
    Posts
    26
    thankz alot

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    and a few tips for successful posts on this board:

    • Use a descriptive title for your thread
    • use code tags (I noticed you attempted to, but forgot the closing tag)
    • make sure your code is formatted nicely (it may have been, but the last code tag was missing)
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    Whats gonna happen now! himanch's Avatar
    Join Date
    Feb 2005
    Location
    Armenia
    Posts
    26
    and one more question!!!!!
    How i am gonna use the Boolean Algebra in the future when i improve my ability and knowledge in programing!!!!!!

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    you'll get a little involved when you get into selection structures (sooner) and maybe more involved when you get into binary operators (later)
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    Whats gonna happen now! himanch's Avatar
    Join Date
    Feb 2005
    Location
    Armenia
    Posts
    26
    thankz

  8. #8
    Pokemon Master digdug4life's Avatar
    Join Date
    Jan 2005
    Location
    Mystic Island, NJ
    Posts
    91
    i just started also, n i am probly worse than you, but in your orignal, i don tthink u need that extra set of braces right under int number;

  9. #9
    Registered User
    Join Date
    Jul 2004
    Posts
    53
    Quote Originally Posted by digdug4life
    i just started also, n i am probly worse than you, but in your orignal, i don tthink u need that extra set of braces right under int number;
    I don't want to be mean but that was a pain to read. Please make a little effort to write at least complete words. And you are right, there is an extra set of curly brackets.

  10. #10
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    The code writer may have just wanted the braces to seperate "working code" from variable declarations and misc. cleanup functions. I know I do the same thing with comments.

  11. #11
    Whats gonna happen now! himanch's Avatar
    Join Date
    Feb 2005
    Location
    Armenia
    Posts
    26
    ok man im gonna try to be neat then since i got so many warnings
    Hayda!!!Whats gonna happen tomorrow

Popular pages Recent additions subscribe to a feed

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