title: Scheme check value if not even
body: <p>I have the following function to check if a positive value is even.</p>
  
  <pre><code>(define (even? n)
      (cond
          ((= n 0) #t)
          ((&lt; n 0) #f)
          (else (even? (- n 2)))
      )
  )
  </code></pre>
  
  <p>I am trying to use this function to increment a store counter when a checked value is not even (odd) using both the <code>even?</code> function and a logical <code>not</code>, but I can't seem to figure out the correct syntax.</p>
  
  <pre><code>(define (function a b)
      (define (iter a b store)
          (cond
              ((= b 1) (+ store a)
              (else
                  (iter (double a) (halve b) (if (not (even? b)) (+ a store) store)))
              )
          )
      (iter a b 0)
  )
  </code></pre>
  
  <p>Could anyone check my syntax to see what I am doing wrong?</p>
  
  <p>A call of <code>(function 1 1)</code> should return 1</p>
  
  <p>A call of <code>(fucntion 1960 56)</code> should return 109760 but I receive 141120</p>
  
  <p>EDIT:
  I realize that my <code>halve</code> funciton must be impromperly defined. I tried to implement a halving function that used only subtraction.</p>
  
  <pre><code>(define (halve n)
      (define (iter src store)
          (cond
              ((&lt;= src 0) store)
              (else (iter (- src 2) (+ store 1)))
              )
          )
      (iter n 0)
      )
  </code></pre>