2

enter image description here

Well I want to made an algorithm to Specify Even or odd numbers this image is my algorithm in Raptor

each time I put a number in it, it gives me "odd" message no matter what number .

what is the problem with this algorithm ? ( image explanation would be better )

Thanks Experts.

The Epic
  • 137
  • 5
  • 1
    Note : `r = 0` implies *even*, not *odd* – Damien Jan 21 '21 at 07:09
  • 1
    Essentially you're doing `q = a/2` and `r = a - (q * 2)`. When you plug in `q` you get `r = a - ( a/2 * 2) = a - a = 0`. This will always be `0`. As per @Damien's answer, you've assigned this to **ODD** whereas it should be **EVEN**. – shapiro yaacov Jan 21 '21 at 07:11
  • 1
    You should be using modulo ("mod") here – shapiro yaacov Jan 21 '21 at 07:13
  • 1
    @shapiro I assumed that integer division is performed (is it true? I don't know Raptor). Then, `r` is equal to `a mod 2` – Damien Jan 21 '21 at 07:15
  • So what should I do now? I dont get it . I actually copy this algorithm form somewhere . would you tell me what should I change to get the true result ? ( my English is not that good ) – The Epic Jan 21 '21 at 07:19
  • @Damien guys help plz – The Epic Jan 21 '21 at 07:26
  • 1
    Invert *Odd* and *Even*, and be sure an integer division is performed here. For example display the value of `q` when `a` is odd – Damien Jan 21 '21 at 07:31
  • 1
    thanks Experts . I replaced " r == 0 " to " q == floor(q) " and I Inverted odd and Even so everything is fine now and my problem solved – The Epic Jan 21 '21 at 07:39

0 Answers0