Computer Science Canada

(TURING) Urgent, need help on multiple choices..

Author:  pink00rock [ Sat Feb 07, 2004 4:18 pm ]
Post subject:  (TURING) Urgent, need help on multiple choices..

Hey!! Sup people? ..

I need help badly.. and i'm so confused with the code i have.

(its a multiple choice question, and i'll show you the problem with it on the buttom)

code:


var answer:string
var counter:int:=0

        put "How many months are there in a year? "
        put " "
        put "a) 13        "
        put "b) 11        "
        put "c) 12        "
        put " "
for i:1..2
        put "Please enter your answer. (type a, b or c)"
        put " "
get answer
if answer = "c" or answer = "C" then
put " ---> Correct! Next Question."
counter:=counter+1
exit
else
put "Sorry, guess again"
end if
end for

%this is it!


The problem is, when the code is outputted. And the user can only guess twice, but on the 2nd wrong guess, it sas "Sorry, guess again" --> (the output)

How many months are there in a year?

a) 13
b) 11
c) 12

Please enter your answer. (type a, b or c)

a
Sorry, guess again
Please enter your answer. (type a, b or c)

b
Sorry, guess again

-------------------

the PROBLEM is --> it says "sorry guess again" twice!
i want it to say something like "Sorry, no more guesses --> next question!"

Can someone please help me, thanks -

Author:  santabruzer [ Sat Feb 07, 2004 4:22 pm ]
Post subject: 

anyways.. ehre is a solution :
code:
var answer : string
var counter : int := 0

put "How many months are there in a year? "
put " "
put "a) 13        "
put "b) 11        "
put "c) 12        "
put " "
for i : 1 .. 2
    put "Please enter your answer. (type a, b or c)"
    put " "
    get answer
    if answer = "c" or answer = "C" then
        put " ---> Correct! Next Question."
        counter := counter + 1
        exit
    elsif i = 1 then
        put "Sorry, guess again"
    elsif i = 2 then
        put "Sorry... Too Bad"
    end if
end for

%this is it!

Author:  Paul [ Sat Feb 07, 2004 4:23 pm ]
Post subject: 

code:

var answer : string
var counter, counter2 : int := 0

put "How many months are there in a year? "
put " "
put "a) 13        "
put "b) 11        "
put "c) 12        "
put " "
for i : 1 .. 2
    put "Please enter your answer. (type a, b or c)"
    put " "
    get answer
    if answer = "c" or answer = "C" then
        put " ---> Correct! Next Question."
        counter := counter + 1
        exit
    else
        if counter2 = 0 then
            put "Sorry, guess again"
            counter2 := 1
        elsif counter2 = 1 then
            put "Wrong, next question"
        end if
    end if
end for

%this is it!

darn it, took too long to copy and paste, but your way is better santabruzer Very Happy

Author:  santabruzer [ Sat Feb 07, 2004 4:26 pm ]
Post subject: 

25 lines.. versus.. 28.. i think we know who the winner is Razz...
ah.. that happens to me often.. too.. at the same time the post...

Author:  Cervantes [ Sat Feb 07, 2004 4:32 pm ]
Post subject: 

lol its the same thing its just else / if or elsif Eh

Author:  santabruzer [ Sat Feb 07, 2004 4:33 pm ]
Post subject: 

and another variable.. really .. really.. it's no different Razz

Author:  TheXploder [ Sat Feb 07, 2004 4:39 pm ]
Post subject: 

or 23 lines:

code:

var answer : string
var counter : int := 0

put "How many months are there in a year? "
put " "
put "a) 13        "
put "b) 11        "
put "c) 12        "
put " "
for i : 1 .. 2
    put "Please enter your answer. (type a, b or c)"
    put " "
    get answer
    if answer = "c" or answer = "C" then
        put " ---> Correct! Next Question."
        counter := counter + 1
        exit
    elsif answer not= "c" and i <= 1 or answer not= "C" and i <= 1 then
        put "Sorry, guess again"
    else
        put "Sorry. Next Question..."
    end if
end for

Author:  .hack [ Sat Feb 07, 2004 5:00 pm ]
Post subject: 

or you could loop it. thats what I have done in the past for my cash register.

if the user enters an payment amount which is less then the subototal it asks for a new payment, enter wrong payments till the cows come home!

Author:  Andy [ Sat Feb 07, 2004 5:01 pm ]
Post subject: 

i smell a competition

code:

var answer : string
var counter := 0
put "How many months are there in a year? \n\na) 13\nb) 11\nc) 12\n"
for i : 1 .. 2
    put "Please enter your answer. (type a, b or c)\n"
    get answer
    if answer = "c" or answer = "C" then
        locate (whatrow - 1, whatcol + 1)
        put " <--- Correct! Next Question."
        counter += 1
        exit
    elsif i = 1 then
        put "Sorry, guess again"
    else
        put "Sorry. Next Question..."
    end if
end for


18 lines plus it looks better

Author:  pink00rock [ Sat Feb 07, 2004 5:33 pm ]
Post subject: 

whoa! thanks guys! lol you guys are wicked at turing.. i wonder how long u been turing for lol. me, only 5 months, but don't practise much..


well thank you once again guys!.. take care - bye!

Author:  TheXploder [ Sat Feb 07, 2004 5:34 pm ]
Post subject: 

competition indeed 15 lines... Laughing

code:

var answer, counter : string := "1"
put "How many months are there in a year? \n\na) 13\nb) 11\nc) 12\n"
for i : 1 .. 2
    put "Please enter your answer. (type a, b or c)\n"
    get answer
    if answer = "c" or answer = "C" then
        put " <--- Correct! Next Question."
        counter += "1"
        exit
    elsif i = 1 then
        put "Sorry, guess again"
    else
        put "Sorry. Next Question..."
    end if
end for

Author:  santabruzer [ Sat Feb 07, 2004 5:34 pm ]
Post subject: 

i've been at turing for i think 4.5 months.. well i had it last sem.. so....

Author:  TheXploder [ Sat Feb 07, 2004 5:36 pm ]
Post subject: 

but then ofcourse for the counter to be right you just need to put this:

code:
put length(counter)-1


instead of the usual one:

code:
put counter

Author:  santabruzer [ Sat Feb 07, 2004 5:39 pm ]
Post subject: 

TheXploder wrote:
code:
put length(counter)-1



wouldn't it use 'strint'?

EDIT: After closer inspection.. nm

Author:  Andy [ Sat Feb 07, 2004 5:54 pm ]
Post subject: 

you should've used strint... have counter:=intstr(strint(counter)+1)

Author:  TheXploder [ Sat Feb 07, 2004 6:56 pm ]
Post subject: 

that's way to complicated to understand...

Author:  Andy [ Sat Feb 07, 2004 8:02 pm ]
Post subject: 

ur the one who wants to do string addition

Author:  TheXploder [ Sat Feb 07, 2004 8:47 pm ]
Post subject: 

but your the one who complicates it my thing works..

Author:  Andy [ Sat Feb 07, 2004 8:48 pm ]
Post subject: 

thats cuz ur thing can only hold count up to 256... mine can do 10^256


: