Thread: Cprogram Input/output parameter HELP

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    39
    Problem : . Function with Input/Output Parameters

    Write a void function called Result that has only two type int input/output parameters. The function will return the sum of the two original parameters through the first parameter. It will also return the differences of the two original parameters through the second parameter.

    Write a main function to test this function


    Need help does not do calculations D:



    Code:
    #include <math.h>
    #include <stdlib.h>
    #include <stdio.h>
    
     
    
    void result(double *smp, double *lgp);
    
    int
    
    main(void)
    
    {
    
              double num1, num2;
              
    
               /* Gets test data */
    
               printf("Enter the first number");
    
               scanf("%lf", &num1);
    
               printf("Enter the second number");
    
               scanf("%lf", &num2);
    
               printf("The first number is %2.f", num1);
    
               printf("The second number is %2.f", num2);
    
               system("pause");
    
               return (0);
    
               }
    
    void
    
    result(double *num2, double *num1)
    
    {
    
                 double temp = *num1;
                  *num1 = *num1 + *num2;
    
                 *num2 = temp - *num2;
    
                           
    }
    it should run like the pic above

  2. #2
    THANK YOU KINDLY SIR Phenax's Avatar
    Join Date
    Mar 2011
    Posts
    74
    Hint: It doesn't do the calculations, because you never told it to do the calculations.
    Quote Originally Posted by Plato
    Never discourage anyone...who continually makes progress, no matter how slow.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    39
    soooooo.....yaaa idk lol im just a beginner in all this :P

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    All the calculations are is getting the sum. So just add the second argument to the first.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    THANK YOU KINDLY SIR Phenax's Avatar
    Join Date
    Mar 2011
    Posts
    74
    Quote Originally Posted by 123456tacos View Post
    soooooo.....yaaa idk lol im just a beginner in all this :P
    C executes the main function by default, and no other function is executed by default. If you want to execute a function that is not main, you have to explicitly do so. You have not explicitly called the function that you have made. C isn't going to automatically figure out what you want the arguments to be and call the function for you.

    Also,
    printf("%.2f", arg); not printf("%2.f", arg);
    Quote Originally Posted by Plato
    Never discourage anyone...who continually makes progress, no matter how slow.

  6. #6
    Registered User
    Join Date
    Feb 2011
    Posts
    39
    ahahaha thanks i got it working DD

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM