It doesn't give the product?? what could be the problem?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xxxDNgirl
    New Member
    • Aug 2011
    • 5

    It doesn't give the product?? what could be the problem?

    Hi! I'm new in turbo C... and I'm trying to make a Program to calculate the product of two numbers.
    please help me! I'm using Turbo C v3.0

    problem:
    when I hit enter for the answer it doesn't give the product, the program closed.... :(

    Code:
    #include<stdio.h> 
                                                                
    int a, b, c;                                                                 
    int product (int x, int y);                                                   
                                                                                
    main()                                                                        
    {                                                                            
    //input first number                                                          
    printf("enter a number between 1 and 100: ");                               
    scanf("%d", &a);                                                                                                              
                       
    //input second number                                                         
    printf("enter another number between 1 and 100: ");                           
    scanf("%d", &b);                                                              
                                                                                 
    c = product(a, b);                                                            
                                                                                
    printf ("%d times %d = %d\n", a, b, c);                                   
                                                                                 
    return 0;
    }                                                        
                         
    int product( int x, int y)                                                   
                                                                                  
    {                                                                             
    return (x * y);                                                               
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Your pogram is working. However, after your answer displays, the program races on to finish main() and stop before your eyes blink.

    You need to add a phony data entry statement at the end of main() to stop the program until you press enter. This will allow you to read the answer.

    Comment

    • xxxDNgirl
      New Member
      • Aug 2011
      • 5

      #3
      what is a phony data entry statement?

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Just do a scanf at the end of main to stop the program for you to enter data. That will allow you time to see your result. Then press enter to complete the program execution.

        Comment

        • xxxDNgirl
          New Member
          • Aug 2011
          • 5

          #5
          thanks a lot! really big help ;)

          Comment

          Working...