Computer Science Canada School asssignment with loop and if help |
Author: | Ultimate_Gio92 [ Thu Dec 13, 2007 7:09 pm ] |
Post subject: | 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 |
Author: | HeavenAgain [ Thu Dec 13, 2007 7:25 pm ] |
Post subject: | 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 _ |
Author: | Tony [ Thu Dec 13, 2007 7:27 pm ] |
Post subject: | Re: School asssignment with loop and if help |
Ultimate_Gio92 @ Thu Dec 13, 2007 7:09 pm wrote: 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! |
Author: | Ultimate_Gio92 [ Thu Dec 13, 2007 8:12 pm ] |
Post subject: | 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 |
Author: | solinent [ Mon Dec 17, 2007 6:54 pm ] |
Post subject: | Re: RE:School asssignment with loop and if help |
Ultimate_Gio92 @ Thu Dec 13, 2007 8:12 pm wrote: 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. |
Author: | Ultimate_Gio92 [ Thu Dec 27, 2007 8:41 pm ] |
Post subject: | RE:School asssignment with loop and if help |
what do you mean solinent? |
Author: | Sean [ Fri Jan 04, 2008 5:42 pm ] |
Post subject: | Re: School asssignment with loop and if help |
I suggest search proper formats for find odd and even.. Hint: Search div under F10 |
Author: | Tony [ Fri Jan 04, 2008 5:53 pm ] |
Post subject: | Re: School asssignment with loop and if help |
Vilament @ Fri Jan 04, 2008 5:42 pm wrote: Hint: Search div under F10
I think you mean mod. Which already has been mentioned 3 times in this thread. |
Author: | Kharybdis [ Fri Jan 04, 2008 5:56 pm ] | ||
Post subject: | Re: School asssignment with loop and if help | ||
That should help. |
Author: | Gooie [ Sat Jan 05, 2008 12:47 am ] | ||
Post subject: | Re: School asssignment with loop and if help | ||
Kharybdis @ January 4th, 5:56 pm wrote:
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! |
Author: | Tony [ Sat Jan 05, 2008 2:07 am ] | ||
Post subject: | RE:School asssignment with loop and if help | ||
![]() |
Author: | Clayton [ Sat Jan 05, 2008 10:37 am ] |
Post subject: | RE:School asssignment with loop and if help |
Damn you Tony. |