1 2 3
|
double c;
double result = 0.0;
for (d=4,c=1;d<=0,c<=5; d--,c++) result += f[d] * (pow (10,c))/10;
|
*cringe*
1) Why the love of pow in situations where it's uncalled for?
2) Why use doubles when you're clearly dealing with ints?
3) Why raise 10 to a power, only to divide by 10 afterwards?
4) The comma operator doesn't work like you expect in that for loop.
d<=0,c<=5
<- doesn't do what you think.
1 and 2 in particular are things you should really work on, BettyBoop. I see pow and unnecessary double<->int conversions all over in the code snippits you post.
Honestly -- pow really is something you should avoid unless necessary. Pretty much all of <cmath> is. Such heavy computations can get expensive.
This code can be greatly simplified:
1 2 3
|
int c = 1;
for(int d = 4; d >= 0; --d, c *= 10)
result += f[d] * c;
|
EDIT:
My intent is not to sound mean BettyBoop. If I come across that way, I really apologize. I actually have a lot of respect for you and appreciate the help you're giving others.
I just want to help you get pointed in more of the right direction is all =)
When I run this code and it get's to that last line again. (which is now return result; it still returns to the start of the function. |
The function is not restarting itself. What's happening is your program is calling this function again after it exits. (EDIT: or your while loop is looping more times than expected? I didn't look that closely at it, honestly)
The problem is not in this function, but is in the function that is calling this function. Can you post how you are calling this?