Help Plz!!!!

This is a discussion on Help Plz!!!! within the C++ Programming forums, part of the General Programming Boards category; Please help me. I wrote a program from one of the tuturiols here. And when i run it. It only ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    7

    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.

  2. #2
    ___
    Join Date
    Jun 2003
    Posts
    806
    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.
    Last edited by ZakkWylde969; 07-14-2003 at 03:53 PM.
    "When I die I want to pass peacefully in my sleep like my grandfather did, not screaming and yelling like the passengers in his car."

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    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
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Read the FAQ .
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    Registered User codingmaster's Avatar
    Join Date
    Sep 2002
    Posts
    309
    @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

  6. #6
    ___
    Join Date
    Jun 2003
    Posts
    806
    Well first I just told him to put his code into the tags. Then I thought I would try to help thank you.
    "When I die I want to pass peacefully in my sleep like my grandfather did, not screaming and yelling like the passengers in his car."

  7. #7
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    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")

  8. #8
    Registered User
    Join Date
    Jul 2003
    Posts
    7
    thx alot guys.

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, 10: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, 01:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21