Computer Science Canada

How do I do this?

Author:  Derpmemes [ Tue Jun 19, 2012 7:40 pm ]
Post subject:  How do I do this?

Write a program to ask the user for an integer, then outputs the first 15 multiples of that number.

I tried using this code:

var integr1:int
var count2:int
put "Give me an integer"
get integr1
for count: integr1..100 by integr1
put count
end for

Please help, I have an exam.

Author:  Beastinonyou [ Tue Jun 19, 2012 8:55 pm ]
Post subject:  Re: How do I do this?

Not sure why that count2 variable is in there; you don't even use it.

Look at your program logically.

What do you need to do: Print first 15 multiples of the number they enter.

This means: Get an integer, and recursively print it's multiples.

The first thing i seen wrong with this is:
Turing:
for count: integr1..100 by integr1

What happens if they enter 200?
What happens if they enter 10, even. You're not even going to get 15 multiples.

Clearly, you want *15* multiples, so you use a for statement

Turing:
var integer : int
put "Enter An Integer" % Less Intimidating than "Give Me An Integer"
get integer
for i : 1 .. 15
     put integer * i
end for


This should be relatively near what you are describing; hope it helps


: