Thread: "easy" C++ help plz

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    15

    Unhappy "easy" C++ help plz

    ok my problem is when i write all the code and then press execute the program work great but when i enter the number to make the program works it close automatically what i coud do to fix this? here is my code:
    (sorry for my english)

    "it was taken of this page but just to learn"




    #include <iostream.h>

    int main()

    {

    int age;

    cout<<"Please input your age: ";

    cin>>age;

    if(age<100)

    {

    cout<<"You are pretty young!";

    }

    else if(age==100)

    {

    cout<<"You are old";

    }

    else

    {

    cout<<"You are really old";

    }

    return 0;

    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Type

    cin.get();

    on the line just before return 0;

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    15

    i know

    but that the problem that if i put cin,get() hapend the same thing


    what u think i could do to fix that?

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    youre using dev right?

    include <stdlib.h>

    then before return 0;

    put
    system("pause");

    note u can use this with other compilers aswell

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >but that the problem that if i put cin,get() hapend the same thing
    You're probably leaving garbage in the input stream from your first call to cin, try this:
    Code:
    #include <iostream.h>
    
    int main()
    {
      int age;
      
      cout<<"Please input your age: ";
      
      cin>>age;
      cin.ignore();
      
      if(age<100)
        cout<<"You are pretty young!";
      else if(age==100)
        cout<<"You are old";
      else
        cout<<"You are really old";
    
      cin.get();
    
      return 0;
    }
    -Prelude
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Jan 2003
    Posts
    15

    ......

    can u recomend me a better compile than this i am think that this one is a piece of ****

    plz recomend me another copile

  7. #7
    Registered User
    Join Date
    Jan 2003
    Posts
    15

    Thx a lot man

    oh thx a lot man but why it dont work for me? this is how i put the cin....:


    #include <iostream.h>

    int main()
    {
    int age;

    cout<<"Please input your age: ";

    cin>>age;
    cin.ignore();

    if(age<100)
    cout<<"You are pretty young!";
    else if(age==100)
    cout<<"You are old";
    else
    cout<<"You are really old";
    cin.get()
    return 0;
    }

  8. #8
    Registered User
    Join Date
    Jan 2003
    Posts
    15

    wich is the diference?

    wich is the diference between yours and mine, why mine dont works?

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    479

    can u recomend me a better compile than this i am think that this one is a piece of ****
    what is the name of your copiler?

  10. #10
    Registered User
    Join Date
    Jan 2003
    Posts
    15

    dev-c++

    dev-c++

  11. #11
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >can u recomend me a better compile than this i am think that this one is a piece of ****
    I haven't had any problems with Dev C++, you just have to get used to the quirks. Besides, you probably won't find a free compiler and IDE of the same quality.

    -Prelude
    My best code is written with the delete key.

  12. #12
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    im stupid how do u spel quote?

  13. #13
    Registered User
    Join Date
    Jan 2003
    Posts
    15

    lol

    lol i am stupid too

  14. #14
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >im stupid how do u spel quote?
    You just did, quote. Though for maximum correctness it would be:

    "I'm stupid, how do you spell quote?"



    -Prelude
    My best code is written with the delete key.

  15. #15
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    -true

    but

    dev can be a pain in the *** sometimes
    i would recomend ms visual c++

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. plz help me...
    By sweetchakri in forum C Programming
    Replies: 1
    Last Post: 03-03-2009, 11:50 PM
  3. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM