Math problem in C

This is a discussion on Math problem in C within the C Programming forums, part of the General Programming Boards category; Code: for(x=1;x<=day;x++){ age=99(log((max(x,hieght)+a)/7); } that is my code ....and here is what i am trying to do computing a luck ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    5

    Math problem in C

    Code:
     for(x=1;x<=day;x++){
    age=99(log((max(x,hieght)+a)/7);
    }

    that is my code ....and here is what i am trying to do


    computing a luck factor, as this is the formula
    99(log(max(the sumation of x=1 as it reaches day)x,hieght)+a/7;

    now thats probably confusing, so basically its asking for the max of when x reaches a specific of either x or hieght i take it.

    Either way my code is faulty, that for loop just wont complie right, any help would be great

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    In C, you can't just stick numbers next to each other for them to be multiplied like you do in algebra.

    This: na
    Is not "n * a".

    Likewise, "99(log....)" is not "99 * (log...)", if that is what you're actually trying to do.


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

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    5
    yea, just starting C....use to java where i can do that ............i put in the opertands like *, but still get like invalid operations
    Last edited by airj56; 09-05-2006 at 04:36 PM.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,337
    Assuming that max() is a function or a macro that takes two arguments .....
    Code:
    for(x=1;x<=day;x++){
    age=99*(log((max(x,hieght)+a)/7);
    }
    One thing to watch is that log() is a math function which takes a double as argument. If all of your variables are of integral type you would need to convert something to double to allow it to work. For example;
    [code]
    Code:
    /* provide an macro that implements max() for discussions sake */
    #define max(a,b) ((a)<(b) ? (b) : (a))
    
    int x, age, hieght, a;
    for(x=1;x<=day;x++){
    age=(int)(99*(log((max(x,hieght)+(double)a)/7));
    }

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,337
    Quote Originally Posted by airj56
    yea, just starting C....use to java where i can do that ............
    Java doesn't allow that either, except in regular expressions (which are strings that are worked on by a library function).

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    5
    alright, well i dont want to sound like an idiot, but like u said something about that max function, i have to define it or something? THats my only other error

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It helps if you actually post the errors and warnings you're getting. If you're getting an 'undefined reference to max', then you'll need to either create a macro for it, as shown above, or make a function for it. In other words, before you use something, your compiler has to know what it is.


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

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    5
    thanks for all ur replys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  2. Help!!c problem in math
    By feelsunny in forum Tech Board
    Replies: 2
    Last Post: 10-06-2007, 03:35 AM
  3. Math Problem....
    By NANO in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 11-11-2002, 03:37 AM
  4. math problem
    By unixOZ in forum Linux Programming
    Replies: 4
    Last Post: 10-19-2002, 12:17 AM
  5. Little math problem
    By Thantos in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-27-2001, 07:44 PM

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