# Math problem in C

• 09-05-2006
airj56
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
• 09-05-2006
quzah
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.
• 09-05-2006
airj56
yea, just starting C....use to java where i can do that ............i put in the opertands like *, but still get like invalid operations
• 09-05-2006
grumpy
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)); }```
• 09-05-2006
grumpy
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).
• 09-05-2006
airj56
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
• 09-05-2006
quzah
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.
• 09-05-2006
airj56