-
Help Plz!!!!
Please help me. I wrote a program from one of the tuturiols here. And when i run it. It only says:"Please input your age" and when i try to input my age it disappears. heres the source.
#include <iostream.h>
int main()
{
int age;
cout<<"Please input your Age";
cin>>age;
if (age<100)
{
cout<<"Your pretty young";
}
else if(age==100)
{
cout<<"You are old";
}
else
{
cout<<"You are really old";
}
return 0;
}
Thanks for your time.
-
Wow man. Code tags. and indent your code!
Edit- It worked fine when I did this
Code:
#include <iostream>
using namespace std;
int main()
{
int age;
cout << "Please input your Age" << endl << endl;
cin >> age;
if (age<100)
{
cout<<"Your pretty young" << endl << endl;
}
else if(age==100)
{
cout<<"You are old" << endl << endl;
}
else
{
cout<<"You are really old" << endl << endl;
}
return 0;
}
Its got some extra space in there and looks odd but works fine.
-
The problem I think is covered in the faq...After you input the age it just runs through the rest of the code without pausing...there's plenty of ways to fix it. Simplest way is just to add another cin at the end (although not the best way). add cin>>age; before return 0 and it will pause, but you will have to enter a value and press enter
-
-
@ZakkWylde969: first telling crap, then edit (yeah... very cool)
using gcc:
Code:
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int age;
cout<<"Please input your Age";
cin>>age;
if (age<100)
{
cout<<"Your pretty young" << endl;
}
else if(age==100)
{
cout<<"You are old" << endl;
}
else
{
cout<<"You are really old" << endl;
}
system("pause"); // or getch();
return 0;
}
read the faq
-
Well first I just told him to put his code into the tags. Then I thought I would try to help thank you.
-
I assume you're running Windows? Then the answer is in The Programming FAQ.
Also see the two posts at the top of the board about how to use code tags, and the guidelines and hints about how to title your post. (Please be specific. i.e. "Please help with disappearing program")
-