Thread: Simple Multiplication Function.

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    4

    Simple Multiplication Function.

    Hi all, i've been staring at this code for 10 minutes now and can't figure out why it won't compile.. Please help:

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    int mult ( int one, int two );
    
    int main ()
    {
    
        int x;
        int y;
    
        printf("Enter number 1 please: \n");
        scanf("%d", &x);
        printf("Enter number 2 please: \n");
        scanf("%d", &y);
        printf("Thank you, the multiplied value is: %d", mult ( int x, int y ));
    }
    
    int mult ( int one, int two )
    {
     return one * two;
    }
    I'm using Netbeans and Cygwin. Thanks

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Remove int and int from this line of code:
    Code:
    printf("Thank you, the multiplied value is: %d", mult ( int x, int y )
    In calls to a function, you don't include the data type. Those go in two places:

    1) The function prototype, typically found above main, and
    2) The function's first line, where the parameters are listed, along with their data type.

    In calls, it's just mult(x,y)
    Last edited by Adak; 10-04-2010 at 01:48 PM.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    4
    Thank you, Adak.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You are quite welcome, and Welcome to the Forum, Admin!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recursive function
    By WatchTower in forum C Programming
    Replies: 11
    Last Post: 07-15-2009, 07:42 AM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM