
-----------------------------------
batgirl13
Mon Oct 06, 2008 9:35 am

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 :)




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


-----------------------------------
Euphoracle
Mon Oct 06, 2008 2:33 pm

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 wif 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:

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

if dir = "F" or dir = "f" then

-----------------------------------
S_Grimm
Tue Oct 07, 2008 8:34 am

Re: help with my program?
-----------------------------------
use 5 arrays of char. then you can print the word backwards or forwards on a whim. [/syntax]

-----------------------------------
isaiahk9
Wed Oct 08, 2008 3:10 pm

RE:help with my program?
-----------------------------------
just to put this out there, use proper titles for threads, please.

-----------------------------------
ecookman
Wed Oct 15, 2008 11:39 am

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
Sat Oct 18, 2008 12:38 pm

Re: help with my program?
-----------------------------------
use 5 arrays of char. then you can print the word backwards or forwards on a whim. 
Arrays are unnecessary. You can just use a decreasing for loop to output individual elements of the string


for decreasing i : length (stringName) .. 1
        put stringName (i)
end for


-----------------------------------
Ktomislav
Sat Oct 18, 2008 4:33 pm

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.
