new to this so i need help with error

This is a discussion on new to this so i need help with error within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <math.h> int main() { int i; double x_i,a_i,D,Q; printf("\n"); for(i=0;i<20;i++) { double k=i; i=1+k; a_i=1.5-log(x_i+1)+0.5*x_i^0.25; x_i=1+i*0.25; ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    25

    new to this so i need help with error

    Code:
    #include <stdio.h>
    #include <math.h>
    int main()
    {
            int i;
            double x_i,a_i,D,Q;
            printf("\n");
            for(i=0;i<20;i++)
            {
                    double k=i;
                    i=1+k;
                    a_i=1.5-log(x_i+1)+0.5*x_i^0.25;
                    x_i=1+i*0.25;
                    printf("i       x_i         a_1\n");
                    printf("_________________________\n");
                    printf("%2d     %.3f        7.5f\n",i,x_i,a_i);
            }
    }
    when i compile this program this is what it says:
    .c: In function 'main':
    :12: error: invalid operands to binary ^ (have 'double' and 'double')
    iacs5.ucsd.edu%
    what does that mean?
    Last edited by Salem; 01-20-2010 at 10:17 PM. Reason: Added [code][/code] tags, learn to use them yourself

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    ^ is NOT how you raise to the power of in C.

    Use the pow() function in math.h
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21