Riffdis
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 1345 |
|
|
| 10 Jan 2012 09:53 PM |
I know basics, I'm currently working on a little script that prints out 1,20 and shows witch numbers are odd or even. I'm not sure if I use an array for this, and I need some help. help plox? |
|
|
| Report Abuse |
|
|
Riffdis
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 1345 |
|
| |
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 10 Jan 2012 10:02 PM |
I remember this question from when I was trying to learn to script lol. . .
Forgot how the wiki showed you how yo do it but here's how I would solve the problem.
for i = 2,20,2 do print(i-1.." odd") print(i.." even") end
Let me look at the wiki version so I can explain it easier |
|
|
| Report Abuse |
|
|
grimm343
|
  |
| Joined: 18 Sep 2008 |
| Total Posts: 2796 |
|
|
| 10 Jan 2012 10:08 PM |
function check(n) if n/2 == math.floor(n/2) then return "even" else return "odd" end end
So, that's just checking it. You wanted to print out numbers 1-20?
for i=1,20,1 do print(i..", "..check(i)) wait() end
|
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 10 Jan 2012 10:17 PM |
for i = 2,20,2 do print(i-1.." odd") print(i.." even") end
Ehhh nvm I think this one is easier and better than the wiki's version of showing you how to do it. Anyways what the script does is it uses a for loop to get up to 20 counting every other number: ------------------------- for i = 2--[[Starts at 2]], 20--[[Ends at 20]], 2--[[Counts by twos (2, 4, 6, 8. . .)]] do ------------------------- The current number(i) is always even(counts by twos) so we know the number under it is going to be odd so we can do: ------------------------- print(i-1.." odd") ------------------------- Then we print i since is going to be even: ------------------------- print(i.." even") ------------------------- and then we use an end to close the for loop: -------------------------- end --------------------------
|
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 10 Jan 2012 10:18 PM |
@grimm;
Hes learning how to script >.< Anyways most of that is just unneccesary |
|
|
| Report Abuse |
|
|
grimm343
|
  |
| Joined: 18 Sep 2008 |
| Total Posts: 2796 |
|
|
| 10 Jan 2012 10:20 PM |
This could teach him, if he didn't already know, about math.floor, as well as calling functions.
Yeah, I know it's unnecessary to have the majority of that. >.> |
|
|
| Report Abuse |
|
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
|
| 10 Jan 2012 10:24 PM |
Forevenand odd, just use mod (aka remainder of division).
if n%2==0 then print("even") else print("odd") end |
|
|
| Report Abuse |
|
|
|
| 10 Jan 2012 10:25 PM |
print("hi")
I script. Trololol.
Lol, nah. Have fun coding. I'm too tired to help much right now. |
|
|
| Report Abuse |
|
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
| |
|