Thread: Problem with the pause function

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001

    Problem with the pause function

    I just started programming again and am starting over with C++. Now I just did an example I found and it is an if/else statement. At the end of the whole program right before the "return 0;" statement, I put the "system ("Pause");" statement. When I ran the example I was able to get to the prompt right before the if/else statement, but when I assigned the variable required for the program to return info to me, it just quit. I know the the "system ("Pause");" is supposed to keep the program open, but am I supposed to put this before I start my actual code or right under the "int main();" function?

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    This is the example.
    ========================================== /////////////////////////////////////////////////////////////
    ////////////If else statement by indigo0086////////
    #include <iostream.h>
    #include <stdlib.h>

    int main()
    int age; //Needs to be assigned a variable
    cout<<"Please input your age: "; //prompts user for age
    cin>>age; //the input is assigned to age
    if (age<100) //If the age is less than 100...
    cout<<"You are pretty young!"; //...displays this
    else if (age==100) //if age is equal "==" to 100...
    cout<<"You are old"; //displays this
    system ("PAUSE"); //This is the line I am having trouble with
    return 0;
    Now I can compile it but when I actually run the program it just opens and closes. But If take it out (the system function), when I put in my age to test it out, it quits. I am using Dev C++ and whenever you create a new document it adds this line above return 0; by default. I Is that is the right place to put it?
    Last edited by indigo0086; 11-03-2001 at 12:45 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  2. Replies: 5
    Last Post: 02-08-2003, 06:42 PM
  3. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  4. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM