
-----------------------------------
Ultimate_Gio92
Thu Dec 13, 2007 7:09 pm

School asssignment with loop and if help
-----------------------------------
var Number : int
loop
    put "Please enter a number from 1 - 10 (enter -1 to exit)"
    get Number
exit when Number = -1    
if Number not= 3
            or
            Number not= 5
            or
            Number not= 7
            or
            Number not= 9
            or
            Number not= 1
            then
        put "Number is even"
        
        elsif Number not= 2
                or
                Number not= 4
                or
                Number not= 6
                or
                Number not= 8
                or
                Number not= 10
                then
            put "Number is odd"
        end if
end if
    end loop

i need help with this because its probably something really obvious im missing.. btw what this is supposed to do is its supposed to ask you for a number input from 1-10 and its supposed to tell you if number is odd or even and when you enter -1 it exits program

-----------------------------------
HeavenAgain
Thu Dec 13, 2007 7:25 pm

RE:School asssignment with loop and if help
-----------------------------------
the or's should be and instead, and you have an extra end if

ALTHOUGH this can be done way easier
and hint is the % (mod) sign, and even number are the numbers that are divisible by _

-----------------------------------
Tony
Thu Dec 13, 2007 7:27 pm

Re: School asssignment with loop and if help
-----------------------------------
its probably something really obvious im missing..
something obvious is extra. You have one if statement, but two "end if" lines.

Also, if number is not odd, you know that it's even -- you don't have to check it the second time.

And there's a simple way to check if any number is even or odd, just divide by 2 and check what the remainder is.

Edit: heh, HeavenAgain keeps on replying just slightly faster than me... again!

-----------------------------------
Ultimate_Gio92
Thu Dec 13, 2007 8:12 pm

RE:School asssignment with loop and if help
-----------------------------------
thanks alot! that helped alot actualy.. im suspended for school so its really hard asking my teacher for help

-----------------------------------
solinent
Mon Dec 17, 2007 6:54 pm

Re: RE:School asssignment with loop and if help
-----------------------------------
thanks alot! that helped alot actualy.. im suspended for school so its really hard asking my teacher for help

Ignore this post, I see that you are already using the modulus operator.

-----------------------------------
Ultimate_Gio92
Thu Dec 27, 2007 8:41 pm

RE:School asssignment with loop and if help
-----------------------------------
what do you mean solinent?

-----------------------------------
Sean
Fri Jan 04, 2008 5:42 pm

Re: School asssignment with loop and if help
-----------------------------------
I suggest search proper formats for find odd and even..

Hint: Search div under F10

-----------------------------------
Tony
Fri Jan 04, 2008 5:53 pm

Re: School asssignment with loop and if help
-----------------------------------
Hint: Search div under F10
I think you mean mod. Which already has been mentioned 3 times in this thread.

-----------------------------------
Kharybdis
Fri Jan 04, 2008 5:56 pm

Re: School asssignment with loop and if help
-----------------------------------
var num : int
get num

if num mod 2 = 0 then
put "That number is even"
end if

That should help.

-----------------------------------
Gooie
Sat Jan 05, 2008 12:47 am

Re: School asssignment with loop and if help
-----------------------------------
var num : int
get num

if num mod 2 = 0 then
put "That number is even"
end if

That should help.

That's my favorite thing about programming, you learn something simple in the beginning, and do some long, repetitive work to make a program run. Then you learn a something new, and you bring your code from 500 lines to 100. Efficiency is fun!

-----------------------------------
Tony
Sat Jan 05, 2008 2:07 am

RE:School asssignment with loop and if help
-----------------------------------

puts "That number is #{(gets.to_i % 2 == 0) ? "even" : "odd"}"

:lol:

-----------------------------------
Clayton
Sat Jan 05, 2008 10:37 am

RE:School asssignment with loop and if help
-----------------------------------
Damn you Tony.
