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

Username:   Password: 
 RegisterRegister   
 help with my program?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
batgirl13




PostPosted: Mon Oct 06, 2008 9:35 am   Post subject: help with my program?

this is my code to make a program that:
- asks for 5 different words.
- asks whether to display them forwards or backwards.
- displays all 5 words, either forwards or backwards depending on user's choice.


any help would be much appreciated Smile



Turing:

var w1, w2, w3, w4, w5 : string
var dir : string
put "Please enter the first word. Type x to exit."
get w1
if w1 := "x" then
    exit
end if
delay (250)
put "Please enter the second word. Type x to exit."
get w2
if w2 := "x" then
    exit
end if
delay (250)
put "Please enter the third word. Type x to exit."
get w3
if w3 := "x" then
    exit
end if
delay (250)
put "Please enter the fourth word. Type x to exit."
get w4
if w4 := "x" then
    exit
end if
delay (250)
put "Please enter the fifth word. Type x to exit."
get w5
if w5 := "x" then
    exit
end if
delay (500)
cls
put "Would you like to see your words printed forwards or backwards? F for forwards, B for backwards."
get dir
if dir = "F" or "f" then
    put w1, ", ", w2, ", ", w3, ", ", w4, ", ", w5
elsif dir = "B" or "b" then
    put %something to make it go backwards here?
w1, ", ", w2, ", ", w3, ", ", w4, ", ", w5
end if
Sponsor
Sponsor
Sponsor
sponsor
Euphoracle




PostPosted: Mon Oct 06, 2008 2:33 pm   Post subject: RE:help with my program?

I'm not understanding the use of the delays. Are they necessary? They're slowing down execution time for no apparent reason. Are they asked for?

Per each if statement regarding w[number], you use the assignment := operator rather than the evaluation = operator. Turing might fix that for you at runtime, but it's bad practice to leave in there, and most other languages are not so forgiving. The correct way to express `if w5 := "x" then` in this case is:

Turing:
if w5 = "x" then


The use of exit is not valid in this context. The exit command exits the current loop structure. You are not currently in a loop structure, therefore you cannot exit it. In this case, the correct command to use would be return, however there are better ways of coding this so there isn't extensive code repetition, but you probably haven't got that far in the course yet. Therefore, at this stage in the game, the correct structure in this case would be:

Turing:
if w5 = x then
    return
end if


Regarding the line at `if dir = "F" or "f" then` and the similar B condition, you have a syntax error. When using an or condition in Turing, you are to specify the full condition each time. The program will not implicitly assume you are applying the or to if dir =. The correct structure in this case would be

Turing:
if dir = "F" or dir = "f" then
S_Grimm




PostPosted: Tue Oct 07, 2008 8:34 am   Post subject: Re: help with my program?

use 5 arrays of char. then you can print the word backwards or forwards on a whim. [/syntax]
isaiahk9




PostPosted: Wed Oct 08, 2008 3:10 pm   Post subject: RE:help with my program?

just to put this out there, use proper titles for threads, please.
ecookman




PostPosted: Wed Oct 15, 2008 11:39 am   Post subject: RE:help with my program?

do you want the order backwards or forwards or the spelling

if you want the order to be back wards list the order when they print back wards like
var backwardsforwards : string

if (backwardsforwards = "backwards") then
then put the order backwards but it seems that is what you have done

hope that helps?
zero-impact




PostPosted: Sat Oct 18, 2008 12:38 pm   Post subject: Re: help with my program?

A\V @ Tue Oct 07, 2008 8:34 am wrote:
use 5 arrays of char. then you can print the word backwards or forwards on a whim. [/syntax]

Arrays are unnecessary. You can just use a decreasing for loop to output individual elements of the string

code:

for decreasing i : length (stringName) .. 1
        put stringName (i)
end for
Ktomislav




PostPosted: Sat Oct 18, 2008 4:33 pm   Post subject: Re: help with my program?

I think you don't know loops, so I would advice you to learn them. When you learn loops it's really easy and then you will probably understand that post above this one.
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  [ 7 Posts ]
Jump to:   


Style:  
Search: