0

How do I structure my code to stop at a specific threshold?

For example, I have a start and end number:

start number: 100
end number: 200

The start number integer should increment in a loop (using a specific formula) until 100 reaches 200. When 100 reaches 200, the loop should stop. However, the number never really reaches 200, because it's not necessarily increasing by 2, the increment is a little random. So instead I may get 198 jumping to 221.

How do I return both numbers, or how do I stop the loop the moment it passes the threshold of 200 and return 221?

This is the code I have written so far...

int start = get_int("start: ");
int end = get_int("end: ");

do
    {
        start = start + ( (float) start /3.0) - ( (float) start /4.0);
        start = round(start);
        year++;
    
    }
    while(end != start);

IfeAyo
  • 1
  • 2

0 Answers0