Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
(TURING) Urgent, need help on multiple choices..
Author Message
pink00rock

Posted: 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

a
Sorry, guess again

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!"

santabruzer

Posted: 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

Posted: 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
santabruzer

Posted: Sat Feb 07, 2004 4:26 pm   Post subject: (No subject)

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

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

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

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

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

Posted: 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

Posted: 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!

Andy

Posted: 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

Posted: 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

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

competition indeed 15 lines...

 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

Posted: 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

Posted: 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

 code: put counter
santabruzer

Posted: 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

Posted: 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: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 2  [ 19 Posts ]
Goto page 1, 2  Next
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: