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

Username:   Password: 
 RegisterRegister   
 True or false quiz program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
versE91




PostPosted: Sun Apr 13, 2014 4:14 pm   Post subject: True or false quiz program

What is it you are trying to achieve?
Trying to create a true or false quiz


What is the problem you are having?
Doesn't display 1/5, 2/5, 3/5 and 4/5 in percentage. It only tells you if you got perfect or if you failed the quiz entirely. If you don't understand what I am saying, run the file.


Describe what you have tried to solve this problem
Haven't tried anything yet


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
I will post the file.

Turing:


N/A



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Sun Apr 13, 2014 6:14 pm   Post subject: Re: True or false quiz program

div performs integer division, meaning the result is truncated at the decimal point (so 4.6 becomes 4 and -3.9 becomes -3).

The division operator / performs real division and returns a real number.

Note that since you want a percentage you can do what you want with div, just make sure you multiply by 100 before dividing (that way you don't lose any information from the truncation)
versE91




PostPosted: Tue Apr 15, 2014 4:14 pm   Post subject: RE:True or false quiz program

Ok fixed it, works like a charm now. Out of curiosity, is there a way I could create this program with fewer lines?
Insectoid




PostPosted: Tue Apr 15, 2014 5:06 pm   Post subject: RE:True or false quiz program

There's absolutely a way to reduce the number of lines. You can move all of the questions to a separate text file and write a single procedure that takes the question and answer as input which prompts for an answer, checks it, outputs a message, and updates the score. Put that in a loop and you can add as many questions as you can think of without changing a single line of code.
Tony




PostPosted: Tue Apr 15, 2014 5:08 pm   Post subject: RE:True or false quiz program

You don't need to type out the same
code:

case answer of
    label "t", "T" :
        put "That is correct"
        counter += 1
    label "F", "f" :
        put "That is incorrect"
end case

part over and over again.

code:

loop
  display question
  collect answer
  score answer
repeat loop

The logic doesn't care what the question is -- it's just data. You are already almost there, by storing all the questions in an array
code:

questions (2) := "Carrots are good for your eyesight."

Which, coincidentally, is not true, depending on the interpretation of the question -- http://www.snopes.com/food/ingredient/carrots.asp
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
TWizard




PostPosted: Thu May 08, 2014 2:27 pm   Post subject: RE:True or false quiz program

Well, with out using file statements you can still reduce lines, by using a for statements. I'd like to recommend looking at what people "might" input, for example, if someone starts using y/n for some odd reason, the program would just fail out.

Also using a loop and clever thinking you could make this repeatable, and possibly random questions!. A fun experience.
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 1  [ 6 Posts ]
Jump to:   


Style:  
Search: