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

Username:   Password: 
 RegisterRegister   
 (TURING) Urgent, need help on multiple choices..
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
pink00rock




PostPosted: 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 -
Sponsor
Sponsor
Sponsor
sponsor
santabruzer




PostPosted: Sat Feb 07, 2004 4:22 pm   Post subject: (No 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!
Paul




PostPosted: Sat Feb 07, 2004 4:23 pm   Post subject: (No 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
santabruzer




PostPosted: Sat Feb 07, 2004 4:26 pm   Post subject: (No 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...
Cervantes




PostPosted: Sat Feb 07, 2004 4:32 pm   Post subject: (No subject)

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




PostPosted: Sat Feb 07, 2004 4:33 pm   Post subject: (No subject)

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




PostPosted: Sat Feb 07, 2004 4:39 pm   Post subject: (No 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
.hack




PostPosted: Sat Feb 07, 2004 5:00 pm   Post subject: (No 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!
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Sat Feb 07, 2004 5:01 pm   Post subject: (No 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
pink00rock




PostPosted: Sat Feb 07, 2004 5:33 pm   Post subject: (No 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!
TheXploder




PostPosted: Sat Feb 07, 2004 5:34 pm   Post subject: (No 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
santabruzer




PostPosted: Sat Feb 07, 2004 5:34 pm   Post subject: (No subject)

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




PostPosted: Sat Feb 07, 2004 5:36 pm   Post subject: (No 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
santabruzer




PostPosted: Sat Feb 07, 2004 5:39 pm   Post subject: (No subject)

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



wouldn't it use 'strint'?

EDIT: After closer inspection.. nm
Andy




PostPosted: Sat Feb 07, 2004 5:54 pm   Post subject: (No subject)

you should've used strint... have counter:=intstr(strint(counter)+1)
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 2  [ 19 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: