#Simple Code Fix

11 messages · Page 1 of 1 (latest)

nocturne drift
#
    for (int i = 0; i <= 100; i++) {
      for (int j = 1; j <= 100; j++) {
        if (((i / j) * 1000) == (int)(real * 1000)) {
          numerator = i;
          denominator = j;
        } else if (((i / j) * 1000) == -(int)(real * 1000)) {
          numerator = -i;
          denominator = j;
        }
      }
    }

this is the code I have right now to approximate some decimal (real) with a fraction, it seemingly works however the loop will continue after finding an approximation and thus leads to bigger fracions. How can I fix this? While loop?

last graniteBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

nocturne drift
#

I've just done a while loop

#

working well

#

however have run into a problem

#

when a quadratic whos 2a > b

#

so when real < 1

#

it doesnt work

#

i fixed it

#

im insane

#

!close