Thread: error:incompatible type for argument 1

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    2

    error:incompatible type for argument 1

    I'm not sure what i'm doing wrong here but you guys might be able to help. i have to:
    Write a program that declares three one-dimensional arrays named price, quantity, and amount. Each array should be declared in the main() and should be capable of holding 10 double-precision numbers. The numbers that should be stored in price are 10.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15, 3.98. The numbers that should be stored in quantity are 4, 8.5, 6, 8.35, 9, 15.3, 3, 5.4, 2.9, 4.8.
    Your program should pass these three arrays to a function called extend(), which should calculate the elements in the amount array as the product of the equivalent elements in the price and quantity arrays (for example, amount[1] = price[1] * quantity[1]). After extend() has put the values into the amount array, the values in the array should be displayed from within main().

    im getting errors on lines 7,18,and 34 but i do not really understand it

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    double price[10]={10.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15, 3.98};
    double quantity[10]={4.0, 8.5, 6.0, 8.35, 9.0, 15.3, 3.0, 5.4, 2.9, 4.8};
    double amount[10];
    double extend(double [],double [],double []);
    
    int main()
    {
        int counter;
        counter=0;
    
        printf("PRICE\t\tQUANTITY\t\tAMOUNT\n");
        printf("_____\t\t________\t\t______\n");
        while (counter<10)
        {
            extend(price[counter],quantity[counter],amount[counter]);
            printf("%2.2f\t\t%2.2f\t\t%f\n",price[counter],quantity[counter], amount[counter]);
            counter++;
        }
        return 0;
    }
    
    double extend(double price[],double quantity[], double amount[])
    {
        int counter;
        counter=0;
        while (counter<10)
        {
            amount[counter]=(price[counter])*(quantity[counter]);
            counter++;
        }
        return (amount[counter]);
    }

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    It is advisable to specify what the errors were. People (whether in forums or not) are not typically good at mindreading. Keep expecting mindreaders here, and you will find you get little help in future.

    On a quick look, the only problem I can see that would upset a compiler is on line 18. That line is passing three values to a function that is expecting three arrays. Remove the "[counter]" from each argument to stop that. Since this is complaining about a mismatch between the declaration of extend(), at line 7 and the usage of it, at line 18, that will possibly explain your compiler giving you error or warning messages referring to both line 7 and line 18.

    The runtime problem I can see is with line 34: it is returning amount[counter]. However, amount is an array with 10 elements, and (after the preceding while loop) count will have a value of 10. Valid indices for a ten-element array run from 0 to 9. Accessing count[10] is invalid - it gives undefined behaviour. Some compilers might warn about this, but not all compilers will.

    If I seem a little harsh it is because, in all cases above, if the compiler is of sufficient quality to complain, the error messages would have been self-explanatory, with only a little effort on your part to interpret the meaning.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    2
    That worked! thanks for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C programming - incompatible argument type
    By COG92 in forum C Programming
    Replies: 23
    Last Post: 10-17-2011, 10:48 PM
  2. Passing Argument from incompatible pointer type
    By AmritxD in forum C Programming
    Replies: 3
    Last Post: 08-15-2010, 03:23 PM
  3. passing argument from incompatible pointer type
    By bhdavis1978 in forum C Programming
    Replies: 5
    Last Post: 03-17-2010, 12:42 PM
  4. passing argument from incompatible pointer type
    By bgalin in forum C Programming
    Replies: 2
    Last Post: 12-06-2009, 07:14 AM
  5. Replies: 3
    Last Post: 07-17-2007, 03:12 PM