Thread: Stoping Program From Terminating Automatically

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    15

    Stoping Program From Terminating Automatically

    I'm a newbie C programmer, but I have worked with Visual Basic and did a little (3-4 days) of a C++ coding book. Currently I am opening my C coding book (with I also only did 3-4 days of last time) to learn to code in C. I hope to gain an understanding of programing so that I can start working on simple, text-based games and then later on, maybe something with graphics. Anyway, on to my question:

    I am using the Miracle C compiler for my work and have just finished a program that takes 2 numbers (supplied by the user) and multiplies them together. The problem is, after I enter the numbers the computer gets the answer and terminates the program. Obviously, this happens so fast that there isn't time to see the answer. (or to know if the answer is even comming out) What can I add in to my program that will tell the computer to wait for me to tell it to terminate? I've pasted my code below:

    PHP Code:
     /* Program to calculate the product of two numbers. */
     #include <stdio.h>
     
     
    int a,b,c;
     
     
    int product(int xint y);
     
     
    int main()
     {
         
    /* Get the first number */
         
    printf("Enter a number between 1 and 100: ");
         
    scanf"%d", &a);
         
         
    /* Get the second number */
         
    printf("Enter another number between 1 and 100: ");
         
    scanf("%d", &b);
         
         
    /* Calculate and display the product */
         
    product(ab);
         
    printf ("%d times %d = %d\n"abc);
         
         return 
    0;
     }
     
     
    /* Function returns the product of the two values provided */
     
    int product(int xint y)
    {
        return (
    y);


  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Or just run it from the command line in the first place.
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    15
    Does it matter where I implement this into my program?

    Thank you by the way.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Does it matter where I implement this into my program?<<
    At the end of main(), just before return 0;

    (I presume you're talking about the "pause" code)
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    15
    Never mind my last post, I got it. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Terminating a GLUT program?
    By glo in forum Game Programming
    Replies: 4
    Last Post: 07-05-2006, 02:37 AM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. Program Terminating With Error On Exit
    By chriscolden in forum C Programming
    Replies: 19
    Last Post: 01-14-2006, 04:40 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. program to automatically edit filenames
    By nate11000 in forum C++ Programming
    Replies: 6
    Last Post: 07-21-2002, 11:51 AM