Computer Science Canada

Help!

Author:  Thanos [ Fri Jan 03, 2003 5:17 pm ]
Post subject:  Help!

Hi everyone, im a beginner Turing Student and was wondering if you could help me with something. You can see what my problem is in the attatchment, thanks for taking ur time to read my msg. Here is my code (yea i know, it's crappy Very Happy) :

code:

var count, sum, sumSq, sumCu := 0



put "      Sum of the       Sum of the squares       Sum of the cubes"
put "N   natural numbers      of the nautral          of the natural"
put "      from 1 to N      numbers from 1 to N     numbers from 1 to N"
put repeat ("_", 80)


loop
    count := count + 1
    sum := sum + count
    sumSq := sumSq + count ** 2
    sumCu := sumCu + count ** 3
    put count ..
    put repeat (" ", 9), sum ..
    put repeat (" ", 20), sumSq ..
    put repeat (" ", 22), sumCu
    exit when count = 10


end loop



Author:  Izzy [ Fri Jan 03, 2003 6:16 pm ]
Post subject: 

Heya.

code:

var count, sum, sumSq, sumCu := 0

put "      Sum of the       Sum of the squares       Sum of the cubes"
put "N   natural numbers      of the nautral          of the natural"
put "      from 1 to N      numbers from 1 to N     numbers from 1 to N"
put repeat ("_", 80)

loop
    count := count + 1
    sum := sum + count
    sumSq := sumSq + count ** 2
    sumCu := sumCu + count ** 3
    put count:2 ..
    put sum:10 ..
    put sumSq:22 ..
    put sumCu:24
    exit when count = 10


end loop


Instead of putting the spaces in which will throw off the spacing when the digits increase (one digit, two and so on) use what i put, take a look at it, i'm sure you can figure out what it does Razz Smile

- Izzy

Author:  Tony [ Fri Jan 03, 2003 6:47 pm ]
Post subject: 

hey Izzy, appretiate you helping people out Very Happy keep it up

additional highlight of the code

put text:10

that :10 means that text will be displayed in a 10 character space. If text is under 10 characters in length, more spaces will be added to display it as a 10 characters string.

Note that if text is more then 10 characters in length, it will still be displayed at full and alighment will be broken.

If user inputs are to be aligned, it might be a good idea to run a sort to find the largest word and align based on its length.

Author:  Izzy [ Fri Jan 03, 2003 6:59 pm ]
Post subject: 

Heya.

I figured I would tell you this aswell, just an expansion on the current subject, and you might need it Question

code:

var a : real := 11.116

put a:10:2


When you add a second : number on it formats the decimal place. So for are real number 11.116 it will hold the 10 spaces for the number then format the decimal place to two digits. Thus the output would be

11.12 (Don't hold me on the spacing Razz)

- Izzy


: