| Sterkenburg - May-30-2006 server time |
| Yup, just have no idea how to round things, even with the round command. Its got me stumped. I'll start a thread later. |
| Furball - May-29-2006 server time |
| Ya, gotta have the spam filter now though. Spammers have gotten really bad these days. Hopefully everything worked out. It seems you've learnt quite a lot more about turing now |
| Sterkenburg - May-29-2006 server time |
| No problemo. I'm replying to a comment made a zillion years ago in a post started a kazillion years ago. Oh well. Edit: Wow I sure didn't know about "var a, b, c, d, e : int" did I? |
| Red Squirrel - Apr-23-2006 server time |
| Sorry about that ban, the spam bot must of thought it was spam because of the lenght of the post. (1st posts that long normally are spam). Again sorry about that. |
| Sterkenburg - Apr-23-2006 server time |
| I'm not really sure if posting entire programs is good etiquette, but whatever. I made this for grade 9 computers class, and as you can probably see, it was a summary for the Turing unit. I pulled my grade up from a 53% at midterms to an 80% at the end of the year, and this here is part of the reason why (albeit a small part). It works anyway. Feel free to steal whatever you want. My teacher made me overcomment everything, but I DID get perfect (or very close to it). % Rob Sterkenburg % December 14, 2005 % TURING SUMMARY ASSIGNMENT % Line that allows me to use GUI statements (background colour, etc.) import GUI in "%oot/lib/GUI" % Puts Turing into graphics mode and declares screen size setscreen ("graphics:1010;690") % Procedure for creating a border procedure border drawfillbox (1, 1, 1008, 10, 55) drawfillbox (1, 1, 10, 688, 55) drawfillbox (10, 688, 1008, 678, 55) drawfillbox (1008, 678, 998, 1, 55) end border % Quiz starting variable var key : string (1) % Answer and scoring variables var Q1_Ans : string var Q1_Score : int Q1_Score := 0 var Q2_Ans : string (15) var Q2_Score : int Q2_Score := 0 var Q3_Ans : string var Q3_Score : int Q3_Score := 0 var Q4_Ans : string var Q4_Score : int Q4_Score := 0 var Q5_Ans : int var Q5_Score : int Q5_Score := 0 var Q6_Ans : string var Q6_Score : int Q6_Score := 0 var Q7_Ans : string var Q7_Score : int Q7_Score := 0 var TotalScore : int % Variable to control how long delays are (shortened for testing). var DelayTime : int DelayTime := 10 %THIS WAS NEVER CHANGED BACK :( % Background colour var BackColour : int BackColour := 255 GUI.SetBackgroundColor (BackColour) % Intro info border colorback (255) color (14) for x : 1 .. 40 cls locate (5, x) put "Welcome to the Rob Sterkenburg Driving Test." border delay (50) end for for decreasing x : 43 .. 7 cls locate (5, 41) put "Welcome to the Rob Sterkenburg Driving Test." locate (x, 38) put "All answers use capital letters and whole numbers." % Calls border procedure border delay (75) end for locate (10, 51) put "Press any key to start." % Calls border procedure border % Command that is fulfilled when any key is pressed locate (11, 62) getch (key) cls % QUESTION ONE locate (3, 1) put "When are roads the slickest? " put " " put "A) After it has rained for at least 20 minutes, and all of the oil, grease, dirt and rain mix together." put "B) When it has just started to rain and the rain hasn't mixed with the substances on the road." put "C) After the rain stops." put "D) Before the rain starts." loop put " " put "Answer: " .. get Q1_Ans : * % Increases score for number of attempts Q1_Score := Q1_Score + 1 % If to determine what to do with 'Q1_Ans' if Q1_Ans = "A" then put "Sorry, A is not the correct answer." elsif Q1_Ans = "B" then put " " put " " put "Yes. The most dangerous time for losing traction during rain is around 20 minutes after the rain starts." % Starts next question delay (DelayTime) cls elsif Q1_Ans = "C" then put "C is not the correct answer." elsif Q1_Ans = "D" then put "D is definately not the correct answer." else colour (12) put "That is not a selectable option. Please put only a capital letter A, B, C, or D." colour (14) end if exit when Q1_Ans = "B" end loop % QUESTION TWO locate (3, 1) put "Wet leaves can make the road very _________" % Loop that forces correct answer to be given before proceeding loop put " " put "Fill in the blank. " .. get Q2_Ans : * % Increases score for number of attempts Q2_Score := Q2_Score + 1 % If statement to offer correct/wrong statements and hint statement if Q2_Ans = "Slick" then put " " put " " put "That is the right answer!" delay (DelayTime) cls elsif Q2_Ans = "Slippery" then put " " put " " put "That is the right answer!" delay (DelayTime) cls elsif Q2_Ans = "Dangerous" then put " " put " " put "That is the right answer!" delay (DelayTime) cls % Statement for any answer that is not correct else put "No, that is not the right answer. Try captializing the first letter of your answer." % Helping hint statement - runs at every wrong answer put "Hint: There are three answers. They are 5, 8 and 9 letters long." end if exit when Q2_Ans = "Slick" exit when Q2_Ans = "Slippery" exit when Q2_Ans = "Dangerous" end loop % QUESTION THREE locate (3, 1) put "What is the leading cause of accidents in winter?" put " " put "A) Ice, snow or slush on roads." put "B) Using improper tires (eg. summer tires or cheap all-season tires)." put "C) Speeding." put "D) Falling asleep." % Loop that forces correct answer to be given before proceeding loop put " " put "The answer is: " .. get Q3_Ans : * % Increases score for number of attempts Q3_Score := Q3_Score + 1 % If to determine what to do with 'Q3_Ans' if Q3_Ans = "A" then put "That is the most common response, but it is not correct." elsif Q3_Ans = "B" then put "That is not the correct answer, though it is often a contributing factor to accidents." elsif Q3_Ans = "C" then put " " put " " put "Yes. Many drivers do not slow down sufficiently during poor conditions." delay (DelayTime) cls elsif Q3_Ans = "D" then put "This is not the correct answer." else colour (12) put "That is not a selectable option. Please put only a capital letter A, B, C, or D." colour (14) end if exit when Q3_Ans = "C" end loop % QUESTION FOUR % Start of stop-sign picture var x : array 1 .. 8 of int := init (400, 400, 435, 485, 520, 520, 485, 435) var y : array 1 .. 8 of int := init (400, 450, 485, 485, 450, 400, 365, 365) drawfillpolygon (x, y, 8, 12) var fontA : int fontA := Font.New ("arial:22") Font.Draw ("STOP", 420, 415, fontA, white) % End of stop-sign picture % Start of question text locate (3, 1) put "You may pass a car on the road if: " put "A) The lines in the middle of the road are solid yellow." put "B) There is one solid line in the middle of the road." put "C) The car you are passing is travelling under 75 km/h" put "D) The lines in the middle of the road are solid only for you." put "E) The line(s) in the middle of the road are broken for you or for both sides." put "F) You are going up a hill." % Loop that forces correct answer to be given before proceeding loop put " " put "The answer is: " .. get Q4_Ans : * % Increases score for number of attempts Q4_Score := Q4_Score + 1 % If to determine what to do with 'Q4_Ans' if Q4_Ans = "A" then put "No. You may not pass on any solid line." elsif Q4_Ans = "B" then put "No. You may not pass on any solid line." elsif Q4_Ans = "C" then put "That answer is not correct." elsif Q4_Ans = "D" then put "No. You may not pass a car if there is a solid line." elsif Q4_Ans = "E" then put " " put " " put "Yes, that is the correct answer." delay (DelayTime) cls elsif Q4_Ans = "F" then put "No. You should NEVER pass going up a hill because there may be a car approaching you can't see." else colour (12) put "That is not a selectable option. Please put only a capital letter A, B, C, or D." colour (14) end if % Exit for correct answer exit when Q4_Ans = "E" end loop % QUESTION FIVE locate (3, 1) put "What is the normal speed in a school zone? (in Km/h)" % Loop that forces correct answer to be given before proceeding loop put " " put "The answer is: " .. get Q5_Ans % Increases score for number of attempts Q5_Score := Q5_Score + 1 % If to determine what to do with 'Q5_Ans' if Q5_Ans < 5 then put "You are not using common sense." elsif Q5_Ans < 20 then put "No, that is a bit slow." elsif Q5_Ans < 40 then put "No, that is a little slow." elsif Q5_Ans = 40 then put " " put " " put "Yes, the speed in a school zone is 40 Km/h." delay (DelayTime) cls elsif Q5_Ans > 41 then put "No, that is a bit fast." elsif Q5_Ans > 60 then put "That is far too fast." elsif Q5_Ans > 80 then put "You are not using common sense." else colour (12) put "That is not a selectable option. Please put only a realistic whole number." colour (14) end if exit when Q5_Ans = 40 end loop % QUESTION SIX locate (3, 1) put "What type of vehicles have blue flashing lights?" put " " put "A) Emergency Vehicles." put "B) Volunteer Firefighters." put "C) Police Vehicles." put "D) Snow Removal Vehicles." put "E) Construction Vehicles." % Loop that forces correct answer to be given before proceeding loop put " " put "Answer: " .. get Q6_Ans : * % Increases score for number of attempts Q6_Score := Q6_Score + 1 % If to determine what to do with 'Q6_Ans' if Q6_Ans = "A" then put "That is incorrect. Emergency vehicles have red and white lights." elsif Q6_Ans = "B" then put "No, that is not the correct answer." elsif Q6_Ans = "C" then put "That is incorrect. Police vehicles (in Ontario) have only red and white lights." elsif Q6_Ans = "D" then put " " put " " put "Yes. Snow removal vehicles are the only vehicles with blue lights." delay (DelayTime) cls elsif Q6_Ans = "E" then put "That is incorrect. Volunteer firefighters' vehicles have green lights." else colour (12) put "That is not a selectable option. Please put only a capital letter A, B, C, D, or E." colour (14) end if exit when Q6_Ans = "D" end loop % SCORING locate (3, 1) put "The results of your test are: " put " " % If statements that determine wether ATTEMPT or ATTEMPTS is to be written put "Question One: ", Q1_Score .. if Q1_Score = 1 then put " attempt." else put " attempts." end if put "Question Two: ", Q2_Score .. if Q2_Score = 1 then put " attempt." else put " attempts." end if put "Question Three: ", Q3_Score .. if Q3_Score = 1 then put " attempt." else put " attempts." end if put "Question Four: ", Q4_Score .. if Q4_Score = 1 then put " attempt." else put " attempts." end if put "Question Five: ", Q5_Score .. if Q5_Score = 1 then put " attempt." else put " attempts." end if put "Question Six: ", Q6_Score .. if Q6_Score = 1 then put " attempt." else put " attempts." end if TotalScore := Q1_Score + Q2_Score + Q3_Score + Q4_Score + Q5_Score + Q6_Score put " " put "The total number of attempts is: ", TotalScore, "." put "Total number of attempts to pass: 6." delay (3000) var font1 : int font1 := Font.New ("serif:18") assert font1 > 0 if TotalScore < 7 then Font.Draw ("You have passed! You may recieve your license!", 375, 600, font1, green) else Font.Draw ("You have failed. Please try again.", 375, 600, font1, brightred) end if |
| Furball - Jan-24-2006 server time | ||
Took me awhile to recognize this post, so sorry for the delay. The error you got was a type mismatch. Rather common syntax error. Your variable userchoice is declared as and integer when it is compared as a string. Change it to var userchoice = string. Mind you, think you already fixed this by now |
| Graham - Jan-23-2006 server time |
| ok good to hear |
| mrtorelli - Jan-23-2006 server time |
| because i could not edit my last post, would just like to say that everything is currently working thanks again furball |
| mrtorelli - Jan-23-2006 server time |
| Thanks so much for that furball, just having one problem, look at the screen shot below, and maybe you can help me with it. http://img392.imageshack.us/img392/6052/error3ge.jpg Thanks so much Stefan EDIT - NEVER MIND I FIXED MY ERROR, JUST HAVING A PROBLEM WITH SOME PUT STATMENTS NOW... ALL POST AGAIN IF I CANT FIGURE IT OUT! |
| Furball - Jan-20-2006 server time |
| Seems reasonable for a final project. Just make sure your teacher gives you an outline of the elements required before you finish your project. You never know, he might be expecting graphics or structures that you'll have to fit into your survey/quiz somehow. I am going to assume that your quiz will be multiple choice with around 1 - 5 possibilities. One thing you can do is write to a screen and use a conditional statement for the possibilities (I assume you're using turing:) Take this into consideration. Suppose the answer to a question was B LOOP print "Your question and selections go here:" If userchoice = "a" or userchoice = "A" then print "Sorry, that is incorrect" exit elsif userchoice = "b" or userchoice = "B" then print "Yes, you are correct" score += 1 (Or score = score + 1) exit elsif userchoice = "c" or userchoice = "C" print "Sorry, that is incorrect" exit elsif userchoice = "d" or userchoice = "D" print "Sorry, that is incorrect" exit else print "Entry is invalid, try again" end if END LOOP That's just an idea to get you started off. I would personally put it in a loop in case a stupid user decides he/she wants to choose the number 50 as an answer. That way it loops back and they get to try again. Any valid answer breaks out of the loop and then the next question is asked, using the same looping structure as shown above. If you really want to impress or show better conditional structures, switch would work better (case structure). Simply because it chews away at the coding and looks much more uniform. I haven't coded in turing in a very long time, so I don't remember the exact syntax for a case structure. If you've learnt it, great, if not, big deal. The trick is to do something similar to this (For the purpose of not sticking to an exact language, i'll just stick to pseudocoding it) LOOP CASE for (UPPERCASE(userinput)) userinput = "A": print "Incorrect answer" userinput = "B": print "Correct answer" score += 1 userinput = "C": print "Incorrect answer" userinput = "D": print "Incorrect answer" userinput = "undefined": print "Invalid entry, please try again" END CASE END LOOP This follows the same idea. Just like the conditional statement shown above, this case statement is being looped for error trapping (User enters in something that's invalid). The case statement has a very important part in it. UPPERCASE, many programming languages have something like this, consult the help file or manuals to find out what code YOUR language uses. What it does, is it uppercases letters. Say the user types in the letter "b", well it will register as invalid because the case thinks that "b" and "B" are different. In order to fix that, we uppercase the letter using a special built in function (If your language supports it, hopefully). uppercase functions wil correct "b" inputes by making them into "B"s, thus making your conditions much easier to compare. If your language does not support uppercasing functions or it does not have any, use the conditional statement method. If you have more programming experience and you know how to use uppercasing functions and case structures, use that instead. Hope this helps |
| Graham - Jan-20-2006 server time |
| We'll see in the end |
| mrtorelli - Jan-20-2006 server time | ||
why would i do something that is hard, why not something that is easy and make it look so good, so it looks hard and then get admazing marks for it ?? |
| Graham - Jan-20-2006 server time |
| eww why dont you try something a little harder for a project worth %15 of ur mark? |
| mrtorelli - Jan-20-2006 server time |
| hey, im making a survey program for a class project, and im going to have it so it asks you a question then takes ur answer, and each question is going to be worth so many points, then at the end it will tell you how much points you have earn kind of thing, anyone have any ideas, or how i could make these real easy?? |