# percent function

Discussion in 'C' started by pein87, Aug 23, 2011.

1. ### pein87New Member

Joined:
Aug 6, 2010
Messages:
173
47
Trophy Points:
0
Occupation:
Web Dev
Location:
Limbo
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:
```double percent(double n,double d)
{
return n / d * 100;
}```

ratio

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

2. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
0
Occupation:
Senior Support Engineer
Location:
England
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?

3. ### ScriptingJohn Hoder

Joined:
Jun 29, 2010
Messages:
421
57
Trophy Points:
0
Occupation:
School for life
Location:
/root
Exactly.

4. ### pein87New Member

Joined:
Aug 6, 2010
Messages:
173
47
Trophy Points:
0
Occupation:
Web Dev
Location:
Limbo
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.

5. ### ManzZupNew Member

Joined:
May 9, 2009
Messages:
278
43
Trophy Points:
0
Occupation:
Production Manager:Software @ ZONTEK
Location:
Sri Lanka