plzzz help me

New Member
Joined
Jul 4, 2004
Messages
35
Best answers
0
when i create a program and compile and run eg this program
#include
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
}
cin.get();
return 0;
}

i put in a age when i have compiled and run it but then when i press returne it closes am i doing anything wrong if i am what and how do i fix it plzz tell me if u know
 
New Member
Joined
Aug 5, 2003
Messages
71
Best answers
0
I'm assuming this is C++?
I'll try to rewrite the program for you but it looks like we have different compilers
#include <iostream.h>
int main(){
int age;
cout << "Input your age: ";
cin >> age;
if(age<100)
cout << "You're pretty young!" << endl;
else if(age==100)
cout << "you're pretty old!" << endl;
else
cout << "You're really old!" << endl;
return(0);
}
 
New Member
Joined
Jul 4, 2004
Messages
35
Best answers
0
thanks i am using c++ but it still wont work it opent tha twindow with the blac kbackground i type a age for example 24 and press returne then the window closes why dose this happen its getting really anoying ive been trying to get this working for about 3 days now when i first started the window closed immediatley so i got told to type this before returne 0;
cin.get();
that stopped the window from closing imediately but it still closes now when i put an age in plzz help me or tell me a good place to get help plzzzz
just found out when i use this
#include <iostream.h> //For cout
#include <string.h> //For many of the string functions
int main()
{
char name[50]; //Declare variables
char lastname[50]; //This could have been declared on the last line...
cout<<"Please enter your name: "; //Tell the user what to do
cin.getline(name, 50, '\n'); //Use gets to input strings with spaces or
//just to get strings after the user presses enter
if(!strcmpi("Alexander", name)) //The ! means not, strcmpi returns 0 for
{ //equal strings
cout<<"That's my name too."<<endl; //Tell the user if its my name
}
else //else is used to keep it from always
{ //outputting this line
cout<<"That's not my name.";
}
cout<<"What is your name in uppercase..."<<endl;
strupr(name); //strupr converts the string to uppercase
cout<<name<<endl;
cout<<"And, your name in lowercase..."<<endl;
strlwr(name); //strlwr converts the string to lowercase
cout<<name<<endl;
cout<<"Your name is "<<strlen(name)<<" letters long"<<endl; //strlen returns
//the length of the string
cout<<"Enter your last name:";
cin.getline(lastname, 50, '\n'); //lastname is also a string
strcat(name, " "); //We want to space the two names apart
strcat(name, lastname); //Now we put them together, we a space in
//the middle
cout<<"Your full name is "<<name; //Outputting it all...
return 0;
}
i type in my first name and press enter it dosent close but when i put my second name in it dose close can someone plz explaine this to me plz
 

Users who are viewing this thread

Top Bottom