
-----------------------------------
naqibaba
Thu Dec 03, 2009 10:21 pm

THe Program works but getting WAY TOO LONG!!!! Is there any way to shorten it.?
-----------------------------------
In this program I am having to quiz a user about the capital city of each province in Canada. The Program should allow the user only 3 guesses only. 

The program is getting way too long if I do it my way.  THIS IS JUST FOR CAPITAL OF ONTARIO. WATCH.



var guess1, guess2, guess3 : string

loop
    put " What is the capital city of Ontario. "
    get guess1
    if guess1 = "Toronto" or guess1 = "toronto" then
        put " Correct answer. "
        exit
    else
        put " Wrong."
    end if
    put " "
    put " What is the capital city of Ontario. "
    get guess2
    if guess2 = "Toronto" or guess2 = "toronto" then
        put " Correct answer. "
        exit
    else
        put " Wrong."
    end if
    put " "
    put " What is the capital city of Ontario. "
    get guess3
    if guess3 = "Toronto" or guess3 = "toronto" then
        put " Correct answer."
        exit
    else
        put " Wrong. No more Try Outs. Bye Bye."
        exit
    end if
end loop



Is there any way I can shorten it so I can do the other 10 provinces in a short amount of time. I would appreciate any kind of help.

-----------------------------------
Tony
Thu Dec 03, 2009 10:33 pm

RE:THe Program works but getting WAY TOO LONG!!!! Is there any way to shorten it.?
-----------------------------------
repeating code. Think about a way of using generic code that can ask about any province, and put _that_ inside a loop that runs 10 times.

(loading data from arrays or files is a typical choice).

-----------------------------------
naqibaba
Thu Dec 03, 2009 10:44 pm

Re: THe Program works but getting WAY TOO LONG!!!! Is there any way to shorten it.?
-----------------------------------
I just saw it and I dont think that its of my level. Can there be an example just to make it easy?

-----------------------------------
Tony
Thu Dec 03, 2009 10:51 pm

RE:THe Program works but getting WAY TOO LONG!!!! Is there any way to shorten it.?
-----------------------------------
You can raise your level with The Turing Walkthrough

-----------------------------------
Kharybdis
Thu Dec 03, 2009 11:30 pm

RE:THe Program works but getting WAY TOO LONG!!!! Is there any way to shorten it.?
-----------------------------------
Try starting with how to use for loops and loops before you get into arrays and records though.

-----------------------------------
Murphman
Fri Dec 04, 2009 1:54 pm

Re: THe Program works but getting WAY TOO LONG!!!! Is there any way to shorten it.?
-----------------------------------
You can shorten your code by alot. You only need to ask the question once in the loop.
Make a Variable called count and declare it as a int, 

var count : int

Now make the count equal 0 out side of the loop

count := 0

now i am gonna let you figure the rest out on your own. this is all i will tell you. You need an exit when, and you also need to make count a counter somewhere in the if.

exit when count = 3

count := count + 1 