Jan 8, 2009 at 11:47pm UTC
Assuming I have a simple output from 1 - 20. How can I output five numbers per line? I'm thinking this is suppose to be easy but I'm definitely having problems. Thanks.
Last edited on Jan 8, 2009 at 11:47pm UTC
Jan 8, 2009 at 11:51pm UTC
Just don't put an endl til after the 5th number.
Jan 9, 2009 at 7:09am UTC
Hey
Here's some pseudocode to help you along:
1 2 3 4 5 6 7 8 9
printNums
for (i in 1..20)
print i
if (i%5==0)
print endl
end if
end for
end printNums
Generally, if you have to do something "every n'th time" you should instantly think "modulo"
Last edited on Jan 9, 2009 at 7:10am UTC
Jan 9, 2009 at 1:16pm UTC
There are multiple ways to solve a problem as well, You could also solve that problem using nested for loops.
Last edited on Jan 9, 2009 at 1:16pm UTC
Jan 10, 2009 at 7:10pm UTC
Thanks guys...appreciate it very much