{"id":55,"date":"2006-08-17T09:42:18","date_gmt":"2006-08-16T21:42:18","guid":{"rendered":"http:\/\/craig.dubculture.co.nz\/blog\/2006\/08\/17\/basic-liability-insurance\/"},"modified":"2010-08-28T17:38:20","modified_gmt":"2010-08-28T16:38:20","slug":"basic-liability-insurance","status":"publish","type":"post","link":"http:\/\/craig.dubculture.co.nz\/blog\/2006\/08\/17\/basic-liability-insurance\/","title":{"rendered":"BASIC liability insurance"},"content":{"rendered":"<p>As those of you who know me personally will know that I am, quite vocally, not someone who enjoys programming.  My main problem is that I write code so infrequently that whenever I sit down I've forgotten either the syntax of language or the parameters of the API, and find more time is taken with reading the docs or finding suitable examples than actually writing or thinking.<\/p>\n<p>I visited my parents yesterday to help my 16 year old brother study for a test, and he also asked for some help with a programming assignment. Due either to a <a href=\"http:\/\/www.firefightingnews.com\/article-NZ.cfm?articleID=12825\">recent loss of computing equipment<\/a>, or general difficulty in deciding on a language for teaching programming, they're using <a href=\"http:\/\/en.wikipedia.org\/wiki\/QBasic\">QBasic<\/a>.  Last time I used QBasic, I hadn't gone through a university degree and learnt half a dozen programming languages, so I found it all a bit easier this time.  The problem was that I had no idea if half of the things I wanted to do had syntax in QB: you can't specify an array using numbers[4] = {1, 3, 6, 8}, so an example on the web (the only time I had to go outside of the help) pointed out that you use READ and a DATA statement.  I remember seeing DATA statements in Commodore 64 code printouts in magazines, and not having any idea how the stuff quite how they worked. Surely it's easier to specify your data inline, rather than in a DATA statement?  Isn't BASIC supposed to be, well, basic?<\/p>\n<p>Anyway, below the fold is what I wrote.  The goal was to teach my brother, and his brief was \"write a roulette game\".  I insisted there would be no GOTOs, and no functions\/subroutines, as he hadn't covered them at school.  Generally the code had to make sense so he could read it and figure out how it all worked.<\/p>\n<p>We finished it, and then, like the bastard I am, I deleted the bit that tests for odd and even and made him rewrite that.  I suspect he'll find this post before actually rewriting it himself.  Maybe not enjoying programming runs in the family.<\/p>\n<p><!--more--><\/p>\n<p><strong>The game<\/strong><\/p>\n<pre>\r\nRANDOMIZE TIMER\r\n' You start with $100 in your hand.  (You are not a high roller.)\r\ncash% = 100\r\n\r\n' build array for which numbers are red, and which are black\r\n\r\nDIM rednumbers(18)\r\nDIM blacknumbers(18)\r\n\r\nFOR i = 1 TO 18\r\n  READ rednumbers(i)\r\nNEXT i\r\n\r\nFOR i = 1 TO 18\r\n  READ blacknumbers(i)\r\nNEXT i\r\n\r\n' red numbers\r\nDATA 1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36\r\n' black numbers\r\nDATA 2,4,5,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35\r\n\r\nCLS\r\nPRINT \"This is Jared's Almost-Roulette!\"\r\nPRINT\r\nPRINT \"Rules of the game: The wheel has the numbers 1-36 and 0.\"\r\nPRINT \"You can bet on odd or even numbers, or any number on the wheel.\"\r\nPRINT\r\nPRINT \"To quit, bet -1.\"\r\nPRINT\r\nbet% = 0\r\n\r\nDO UNTIL bored\r\n  DO UNTIL bet% &gt; 0\r\n    INPUT \"How much do you want to bet?  $\", bet%\r\n    ' check that we aren't spending more money than we have\r\n    IF bet% = -1 THEN\r\n      PRINT \"Thanks for playing.\"\r\n      END\r\n    END IF\r\n    IF bet% &gt; cash% THEN\r\n      PRINT \"You only have\"; cash%; \".\"\r\n      bet% = 0\r\n    END IF\r\n  LOOP\r\n\r\n  PRINT \"You are betting $\"; bet%\r\n  cash% = cash% - bet%\r\n\r\n  num% = INT(RND * 37)\r\n  PRINT \"the number is... \"; num%; \"!\"\r\n\r\n  correctchoice = 0\r\n  DO UNTIL correctchoice = 1\r\n\r\n    INPUT \"Please type in a number between 0 and 36, or one of 'odd even red black': \", choice$\r\n    ' Check your input is valid\r\n    ' numbers (1-36)\r\n    ' odd or even\r\n    ' zero, which needs to be separate, because of qbasic\r\n    IF (UCASE$(choice$) = \"ODD\") OR (UCASE$(choice$) = \"EVEN\") OR (UCASE$(choice$) = \"RED\") OR (UCASE$(choice$) = \"BLACK\") OR (VAL(choice$) &gt;= 1 AND VAL(choice$) &lt;= 36) OR (choice$ = \"0\") THEN\r\n      correctchoice = 1\r\n    ELSE\r\n      PRINT \"Please type one of 'odd even red black', or a number between 0 and 36.\"\r\n    END IF\r\n  LOOP\r\n\r\n  ' the computer spins the wheel.\r\n\r\n' possible things that happen:\r\n' 1. you picked odd or even - check to see if you won and pay out 2* bet\r\n' (remember to exclude 0)\r\n' 2. you picked red or black\r\n' 3. you picked a number, you either win 36:1 or you don't.\r\n\r\nIF UCASE$(choice$) = \"ODD\" THEN\r\n  IF num% MOD 2 = 1 THEN\r\n    PRINT \"It was odd: you win $\"; 2 * bet%\r\n    cash% = cash% + 2 * bet%\r\n  ELSE\r\n    PRINT \"The number is even, so you win nothing.\"\r\n  END IF\r\nEND IF\r\n\r\nIF UCASE$(choice$) = \"EVEN\" THEN\r\n  IF num% MOD 2 = 0 AND num% &lt;&gt; 0 THEN\r\n    PRINT \"It was even: you win \"; 2 * bet%\r\n    cash% = cash% + 2 * bet%\r\n  ELSE\r\n    PRINT \"The number is odd, so you win nothing\"\r\n  END IF\r\nEND IF\r\n\r\nIF UCASE$(choice$) = \"RED\" THEN\r\n  match = 0\r\n  FOR i = 1 TO 18\r\n    IF num% = rednumbers(i) THEN\r\n      match = 1\r\n    END IF\r\n  NEXT\r\n  ' if match = 1, then our number is in the red array\r\n  IF match = 1 THEN\r\n    PRINT \"It was red!: you win \"; 2 * bet%\r\n    cash% = cash% + 2 * bet%\r\n  ELSE\r\n    PRINT \"The number is not red, so you win nothing\"\r\n  END IF\r\nEND IF\r\n\r\nIF UCASE$(choice$) = \"BLACK\" THEN\r\n  match = 0\r\n  FOR i = 1 TO 18\r\n    IF num% = blacknumbers(i) THEN\r\n      match = 1\r\n    END IF\r\n  NEXT\r\n  ' if match = 1, then our number is in the black array\r\n  IF match = 1 THEN\r\n    PRINT \"It was black!: you win \"; 2 * bet%\r\n    cash% = cash% + 2 * bet%\r\n  ELSE\r\n    PRINT \"The number is not black, so you win nothing\"\r\n  END IF\r\nEND IF\r\n\r\nIF num% = VAL(choice$) THEN\r\n  PRINT \"Your number came up!\"\r\n  PRINT\r\n  PRINT \"You win \"; 36 * bet%\r\n  cash% = cash% + 36 * bet%\r\nEND IF\r\n\r\n  PRINT \"You now have $\"; cash%; \"in your hot little hand.\"\r\n  PRINT\r\n  IF cash% = 0 THEN\r\n    PRINT \"You should stop playing now, else you'll end up betting\"\r\n    PRINT \"your gold watch, then borrowing money you can't pay back\"\r\n    PRINT \"then getting kneecapped in the alleyway outside.\"\r\n    END\r\n  END IF\r\n  bet% = 0\r\nLOOP\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>As those of you who know me personally will know that I am, quite vocally, not someone who enjoys programming. My main problem is that I write code so infrequently that whenever I sit down I've forgotten either the syntax of language or the parameters of the API, and find more time is taken with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[67,66],"tags":[3],"_links":{"self":[{"href":"http:\/\/craig.dubculture.co.nz\/blog\/wp-json\/wp\/v2\/posts\/55"}],"collection":[{"href":"http:\/\/craig.dubculture.co.nz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/craig.dubculture.co.nz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/craig.dubculture.co.nz\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/craig.dubculture.co.nz\/blog\/wp-json\/wp\/v2\/comments?post=55"}],"version-history":[{"count":1,"href":"http:\/\/craig.dubculture.co.nz\/blog\/wp-json\/wp\/v2\/posts\/55\/revisions"}],"predecessor-version":[{"id":396,"href":"http:\/\/craig.dubculture.co.nz\/blog\/wp-json\/wp\/v2\/posts\/55\/revisions\/396"}],"wp:attachment":[{"href":"http:\/\/craig.dubculture.co.nz\/blog\/wp-json\/wp\/v2\/media?parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/craig.dubculture.co.nz\/blog\/wp-json\/wp\/v2\/categories?post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/craig.dubculture.co.nz\/blog\/wp-json\/wp\/v2\/tags?post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}