Thread: Help

  1. #1


    ok, i have a program where u enter a variable and whenever i put it in and press enter, my program closes instead of displaying the rest of the prgram....PLEAS HELP

  2. #2

    heres the code, i almost forgot

    #include <iostream.h>
    int main() //Most important part of the program!
    int age; //Need a variable...
    cout<<"Please input your age: "; //Asks for age
    cin>>age; //The input is put in age
    if(age<100) //If the age is less than 100
    cout<<"You are pretty young!"; //Just to show it works
    else if(age==100) //I use else just to show an example
    cout<<"You are old"; //Just to show you it works...
    cout<<"You are really old"; //Executed if no other statement is executed
    return 0;


  3. #3
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    works fine when i run it. what's your compiler? if it's msvs you may be entering your code in the wrong file (i remember having the same trouble, but i can't recall what i did to fix it). i think the computer is closing the console too fast for you to see the end results. but your program works fine

    code tags use []'s not <>'s

  4. #4
    I'm Back
    Join Date
    Dec 2001
    if i understood correctly your problem, you'll have to put getch() in conio.h [compiler specific] just before return 0.

    this will wait for a user keypress after displaying your text.

    you could do a search on "wait for user input" and find something to your liking.

  5. #5
    include <stdlib.h> then you can just use: system("PAUSE");

  6. #6
    Registered User
    Join Date
    Apr 2002
    or getchar() with <iostream.h>
    Last edited by lostminds; 05-02-2002 at 03:33 AM.
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

Popular pages Recent additions subscribe to a feed