-
A simple loop question
Hello all!
I want a loop from A to B (B > A) including both endpoints A and B, with a given number of steps, for example (B-A)/steps. If I say
Code:
double A = 1.25f;
double B = 7.12f;
double step = 100f;
for(double i = A; i < B; i += step) { }
the endpoint B is excluded. What is the right way to do this?
serge
-
Code:
#include <iostream>
using namespace std;
int main() {
double A = 1.25;
double B = 7.12;
int steps = 10;
double step = ( B - A )/( steps - 1);
for(int i = 0; i < steps; ++i ) {
cout << A + step * i << endl;
}
}
Kurt