Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   percent function (http://www.go4expert.com/forums/percent-function-t26552/)

 pein87 23Aug2011 06:10

percent function

I've been playing with the notion of making my own game engine and these are some starter functions I wrote for in game stats.

percentage

Code: C++

`double percent(double n,double d){return n / d * 100;}`

ratio

Code: C++

`double ratio(double n,double d){return n / d;}`

 xpi0t0s 23Aug2011 11:19

Re: percent function

It's a bit pointless having a function that just takes one line of code. Better just to use those single lines of code instead of calling the function; it looks here as if you're trying to rewrite C in some other language, which doesn't work. A function should do something useful, not just redefine an operator. Also the parameter names should be descriptive. n and d mean nothing. Do you mean numerator and denominator?

 Scripting 23Aug2011 16:23

Re: percent function

Quote:
 Originally Posted by xpi0t0s (Post 86306) It's a bit pointless having a function that just takes one line of code. Better just to use those single lines of code instead of calling the function; it looks here as if you're trying to rewrite C in some other language, which doesn't work. A function should do something useful, not just redefine an operator. Also the parameter names should be descriptive. n and d mean nothing. Do you mean numerator and denominator?
Exactly.

 pein87 24Aug2011 02:00

Re: percent function

Its easier to just supply the arguments to the function. This belongs to a class for all my stats. I don't see how I'm rewriting the language if I'm using standard C++. You have the name for n and d correct as the params though.

 ManzZup 25Aug2011 21:28

Re: percent function

i think there's actually a objective in what pein87 is doing
as he said that he is using those functions in game there are several uses
1: can prevent the repeat of the code though it is single line, this makes the code more readeable
2: he can add what ever additions to the function body to change the output which is VERY much easier in contrast with replacing all the lines

 All times are GMT +5.5. The time now is 00:35.