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

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




PostPosted: Thu May 21, 2009 8:35 pm   Post subject: Turing Program

Hi I have to make a proram for my compsci class and I keep running into problems could anyone please point me in the right direction

ok this is the problem
Write a program which will display a conversion table from miles to kilometers (1 mile = 1.6 km) Design the program so that the values for miles increases by 5. The table will start with 5 and end with 100 miles.

Your output will look like this
Miles Kilometers
5 8.0
10 16.0
15 24.0
... ....
... ...
.. ....
100 160

This is my code so far:

for count : 5..10
var miles:= count ** 5
var kilometers: real
kilometers:= miles * 5.6
put "Miles ", miles, " Kilometers ", kilometers
end for

If anyone could please teach me what to do I dont want you to just write the code for me, I just need help in making MY code work so if someone could please point out the error in my code that would be much appreciated.

Thanks for any help
slider203
Sponsor
Sponsor
Sponsor
sponsor
DtY




PostPosted: Thu May 21, 2009 8:40 pm   Post subject: RE:Turing Program

For allows you to increment by values other than one, I think it looks like:

for count: 1..10 by 5
%Do stuff
end for

[edit] I think the only problem with your program above is that you're using exponents (**) instead of multiplication (*)
Zren




PostPosted: Thu May 21, 2009 11:24 pm   Post subject: Re: Turing Program

Try and think of it functionally (or graphically). The variable miles would be the dependant variable. So if you did what DtY said, you could eliminate count and call it miles instead (miles would increase by 5 till it reaches ____).

for miles : 5 .. ____

Then you'd convert miles to kilometers. I think your a little confused with this part because of this:

"kilometers:= miles * 5.6 "

Right now if miles = 5, kilometers would equal 28. Not what we're looking for. So how does 1 convert to 1.6? And 5 to 8?
agnivohneb




PostPosted: Fri May 22, 2009 2:03 am   Post subject: Re: Turing Program

You are close, I think you are over complicating the problem.

You have it right that you need to use a counted loop but you may want to try from 5 to 100 by 5 instead of 5 to 10 and then doing extra math.

Inside that loop you really don't need to use any variables all you need to do is output this (and note this is in sudocode because I am not giving you the complete answer).
Output: "Miles " [count] " KM " [count x 1.6]

Thats it. It should be exactly 3 lines when done.
agnivohneb




PostPosted: Fri May 22, 2009 2:10 am   Post subject: Re: RE:Turing Program

DtY @ Thu May 21, 2009 8:40 pm wrote:
for count: 1..10 by 5
%Do stuff
end for


If you were to use that then it would only output 1 and 6. It should be 5 to 100 by 5 to output 5, 10, 15, 20, 25...95, 100.

Just pointing that out. Smile
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  [ 5 Posts ]
Jump to:   


Style:  
Search: