#include <iostream>
using namespace std;
int main() {
float result = 50.0f;
float multiplier = 0.5f;
float fixed_multiplier = 1.0f - multiplier * 0.001f;
for (int i = 0; i < 1000; ++i) {
result *= fixed_multiplier;
}
cout << result << endl; // 30.322 -- want approximately 25
}
After the 1000 iterations, I want result to equal multiplier*result (result==25). How do I find what I need to modify multiplier (in fixed_multiplier) to get the desired result?
Your
forloop is summarized by this mathematical equation:You can solve this equation to find your answer.
You can get the same result in C using the
powfunction: