Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Thanos




PostPosted: 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





turing problem.JPG
 Description:
 Filesize:  116.58 KB
 Viewed:  6006 Time(s)

turing problem.JPG


Sponsor
Sponsor
Sponsor
sponsor
Izzy




PostPosted: Fri Jan 03, 2003 6:16 pm   Post subject: (No 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
Tony




PostPosted: Fri Jan 03, 2003 6:47 pm   Post subject: (No 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Izzy




PostPosted: Fri Jan 03, 2003 6:59 pm   Post subject: (No 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: