Thread: Funcation Call

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    102

    Funcation Call

    My lecturer just taugh me function call. Anyway how do I get two value from user (vis scanf) then assign the value into the function call for calculation. Now 8 and 10 is fixed.

    Code:
    #include<stdio.h>
    int sum(int x, int y){
    	int sum = x+ y;
    	return sum;
    }
    int main(){
    
    int y;
    
    sum(8,10);
    y=sum(8,10);
    
    printf("Sum is %d", y);
    
    getchar();
    
    }
    Thanks!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Things are handled in top down order. So, write one line at a time on paper the steps you need:

    1. Get info from user.
    2. Send it to my function.

    You aren't doing that. Give it a try.

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

  3. #3
    Registered User
    Join Date
    Aug 2011
    Posts
    102

    RE

    Is it like this?
    Code:
    #include<stdio.h>
    int sum(int x, int y){
    	int sum = x+ y;
    	return sum;
    }
    int main(){
    
    int y;
    int num1;
    int num2;
    
    printf("Value:\n")
    scanf("%d %d",sum(&num1, &num2));
    
    
    y=sum(8,10);
    
    printf("Sum is %d", y);
    
    getchar();
    
    }
    But still not working.I'm not very sure of 2. Send it to my function. Thanks

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No. Stop trying to stick everything together in a single line:

    1. Get 2 values from someone.
    2. Pass those values to a function.

    Don't try to stick one and two into the same step, just do one at a time.


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

  5. #5
    Registered User
    Join Date
    Aug 2011
    Posts
    102

    Thanks

    I just solved it. Thanks! It should be something like this

    Code:
    printf("Total: %d\n", mul(num1, num2));

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help!! call-by-reference and call-by-value
    By geoffr0 in forum C Programming
    Replies: 14
    Last Post: 04-01-2009, 07:15 PM
  2. C system call and library call
    By Coconut in forum C Programming
    Replies: 6
    Last Post: 08-22-2002, 11:20 AM
  3. System call to call another C file from Existing C File
    By simly01 in forum C++ Programming
    Replies: 2
    Last Post: 07-31-2002, 01:29 PM
  4. Call-by-value Vs. Call-by-reference
    By Wiz_Nil in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2002, 09:06 AM
  5. call by reference and a call by value
    By IceCold in forum C Programming
    Replies: 4
    Last Post: 09-08-2001, 05:06 PM