|
How to
Jun 19, 2005 14:57:56 GMT
Post by Edwin on Jun 19, 2005 14:57:56 GMT
;D Ok this one is kind of weird, I wrote a program that ask a question and the user can only reply with True or False. There are seven of these questions, what I want to learn next is to tally up the results and display the results with a comments of Perfect, Excellent, or Try again. How can I do this?
|
|
|
How to
Jun 19, 2005 17:41:52 GMT
Post by Buff1 on Jun 19, 2005 17:41:52 GMT
Post your code. We will help.
We get so many requests to do homework we are somewhat reluctant to write programs versus help on code posted.
|
|
edwin
New Member
Posts: 8
|
How to
Jun 19, 2005 18:38:30 GMT
Post by edwin on Jun 19, 2005 18:38:30 GMT
Well it's not home work school or nothing I bought a book call, A brief course in QBASIC, by David I. Schneider. The examples are great, but it has a lot of practice exercises that don't show the results. I figured out 3/4 of the book, but its still new material for me. But I will get there. Still haven't learned all two hundred preprogramed codes yet, and this book only has half. Any ways here's what I came up with.
REM Proverbs and Truth Values CLS DIM value$(1 To 3) LET total = 0 FOR proverbs = 1 TO 3 LET total = total NEXT proverbs
PRINT "Answer the following True or False: "
INPUT "The squeaky wheel gets the grease"; value$ SELECT CASE value$ CASE ELSE PRINT "True or False only" END SELECT
CLS INPUT "Cry and you cry alone"; value$ SELECT CASE value$ CASE ELSE PRINT "True or False only" END SELECT
CLS INPUT "Spare the rod and spoil the child"; value$ SELECT CASE value$ CASE ELSE PRINT "True or False only" END SELECT
REM Read values and total the score
IF total = 3 THEN PRINT "Perfect" END IF
IF total = 2 THEN PRINT "Excellent" END IF
IF total = 1 THEN PRINT "You might consider Psychology 101" END IF END
I wrote the short version, but as you can see I am missing something, maybe a READ or whatever, I can make this work if it were numbers but the practice exercise says to use words
oh by the way just point me in the right direction, I learn by doing, but I really do appreciate that I get help. These books don't explain as much as I would like to see. Thanks again. What I also need to know is did I use the wrong format all together.
|
|
buff1
New Member
Posts: 3
|
How to
Jun 19, 2005 22:56:36 GMT
Post by buff1 on Jun 19, 2005 22:56:36 GMT
Well I thought I had posted the message but something must have happened (maybe i clicked the wrong buttong)
Don't use LET (noone uses it anymore)
1. The for loop for proverbs=1 to 3 does nothing since it sets total to 0 each time eliminate it (not needed)
2. In your select case add CASE "T" and CASE "F" (or "TRUE" and "FALSE" depending on what you want)
Under the case that is correct add the line TOTAL=TOTAL+1
That should do it.
The only other comment would be if you want to allow them to reenter the T/F if they enter something else you would have to (in your code) use a goto to go back to the appropriate input statement
Another way would be to use a while loop for example encompassing the input statement and select case for each true/false until they answer appropriately
|
|
edwin
New Member
Posts: 8
|
How to
Jun 20, 2005 2:22:14 GMT
Post by edwin on Jun 20, 2005 2:22:14 GMT
Thanks for the info, I was surfing around and found another way to write the program, but I checked the corrections you made, it made life much easier, now I have two ways of doing it. I still have learn to think outside of the box. Where can I get info on Qbasic statements beside the F1?
|
|
|
How to
Jun 20, 2005 5:15:37 GMT
Post by Buff1 on Jun 20, 2005 5:15:37 GMT
I think in most cases the help (F1) is the best. There are some tutorials around just check out the qb web sites. I think I may have 1 or 2 on mine thunder.prohosting.com/oasys/frameex1.htmon the links page. Best way I have found to learn is to look at other code. QB45.com has a lot and the ALLBASIC archives.
|
|
|
How to
Jun 20, 2005 9:22:15 GMT
Post by Mikrondel on Jun 20, 2005 9:22:15 GMT
As you write more complicated programs, it will become almost impossible to take a case-by-case approach. By this I mean it's impractical write code to check the answers for every question if you have a list of 100 questions. The solution? Make a question-asking engine. In other words, make some code that you simply supply with a question and answer (for example by putting them in variables) and it just does the question and answer checking. Let's have a go now: PRINT Question$ INPUT "", value$ IF value$ = answer$ THEN PRINT "Correct!" Total = Total + 1 ELSE PRINT "Incorrect." END IF Obviously this is very simple and will take anything as wrong if it isn't the answer. If you only wanted True or False that could also be checked for. Personally, for any multiple-choice or True/False questions I'd use a menu that you can select answers from using the arrow keys, both to make it easier for the user and removing the need for error-checking. (And the user can't accidenatlly type Ture or something like that) Now to make a simple loop out of it: DO READ Question$ IF Question$ = "*" THEN EXIT DO READ answer$ <Ask question and check> LOOP PRINT "That's it. You got" Total "correct." END DATA "How many letters are there in the answer to this question?", "Four" DATA "What is Donald Duck's middle name?", "Fauntleroy" DATA "True or false: I am a banana.", "True" DATA "What is the answer to this question", "What" DATA "*" Obviously the star tells QB when to stop READing, so you can add as many questions as you like without adding 8 lines to the program each time. Obviously this is just a rough framework for you to play with and improve... I'll give you a hint, the UCASE$(string) function returns a copy of string with all lowercase letters converted to uppercase. Using this appropriately you can make answers case-insensitive. Anyway, good luck with it all. If you want, you can get my QB tutorial from here: www.autopack.com/aleks/host/QB_A_1.TXTIt's a tutorial for beginners but it explains things in much more detail than most programming introductions, so you can probably learn something from it. See you later.
|
|
edwin
New Member
Posts: 8
|
How to
Jun 20, 2005 11:30:20 GMT
Post by edwin on Jun 20, 2005 11:30:20 GMT
Hey, Mikrondel, thanks for the guide, it does explain things a little better
|
|