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
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
<code>
#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...
}
else
{
cout<<"You are really old"; //Executed if no other statement is executed
}
return 0;
}
</code>
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
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.
-
include <stdlib.h> then you can just use: system("PAUSE");
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."