Hi,(adsbygoogle = window.adsbygoogle || []).push({});

I am trying to write a simple recursive function for calculating money in the bank after a certain amount of years.

However i run into trouble since i need the new_base variable to be static(i need it to "remember" the base from the previous run) But trying to compile the program i get the error:

"Initializer element is not constant"

How would you solve this?

Code (Text):

double recursive(double base, int runs) {

static double m_rate = 1 + (10/100); /* Ten percent interest*/

double new_base = (base*m_rate);

if (runs != 0)

return recursive(new_base,runs-1);

else

return new_base;

}

int main() {

printf("%.2f",recursive(100,10));

return 0;

}

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Calculating interest C

Loading...

Similar Threads for Calculating interest |
---|

Program that calculates the list of x and f(x) for a given function |

Python Interesting article how to use Pandas with Excel sheets |

Symbolic calculations in MATLAB |

Python Insert data into excel, calculate+retrieve data using Python |

**Physics Forums | Science Articles, Homework Help, Discussion**