Chte 5: You Pogm Asks fo Advce. Pge 63 Chte 5: You Pogm Asks fo Advce. Ths chte ntoduces new tye of ves (stng ves) nd how to get text nd numec esonses fom the use. Anothe Tye of Ve The Stng Ve: In Chte 3 you got to see numec ves, whch cn ony stoe whoe o decm numes. Sometmes you w wnt to stoe stng, text suounded y quotton mks ("" o ''), n the comute's memoy. To do ths we use new tye of ve ced the stng ve. A stng ve s denoted y endng do sgn $ on ve nme. You my ssgn nd eteve vues fom stng ve the sme wy you use numec ve. Rememe, the ve nme, cse senstvty, nd eseved wod ues e the sme wth stng nd numec ves. 1 2 3 4 5 6 7 8 9 10 11 # c5_kejm.ks # I ke jm stng ves nme$ = "Jm" fstmessge$ = '"' nme$ '" s my fend.' secondmessge$ = "I ke " nme$ "." nt fstmessge$ sy fstmessge$ nt secondmessge$ sy secondmessge$ Pogm 26: I Lke Jm "Jm" s my fend. 2014 Jmes M. Reneu (CC BY-NC-SA 3.0 US)
Chte 5: You Pogm Asks fo Advce. Pge 64 I ke Jm. Sme Outut 26: I Lke Jm Stng ve A stng ve ows you to ssgn nme to ock of stoge n the comute's shot-tem memoy. You my stoe nd eteve text nd chcte vues fom the stng ve n you ogm. A stng ve nme must egn wth ette; my contn ettes nd numes; e cse senstve; nd ends wth do sgn. Aso, you cn not use wods eseved y the BASIC-256 nguge when nmng you ves (see Aendx I). Exmes of vd stng ve nmes ncude: d$, c7$, ook$, X$, nd nyd$. If you ssgn numec vue to stng ve, BASIC-256 w convet the nume to stng of chctes nd ssgn t to the ve. If you ttemt to ssgn stng to numec ve, you w eceve syntx eo. Inut Gettng Text o Numes Fom the Use: So f we hve tod the ogm eveythng t needs to know n the ogmmng code. The next sttement to ntoduce s. The sttement ctues ethe stng o nume tht the use tyes nto the text e nd stoes tht vue n ve. 2014 Jmes M. Reneu (CC BY-NC-SA 3.0 US)
Chte 5: You Pogm Asks fo Advce. Pge 65 Let's tke Pogm 26 nd modfy t so tht t w sk you fo nme nd then sy heo to tht eson. 1 2 3 4 5 6 7 8 9 10 11 # c5_ke.ks # usng to sk fo nme "ente you nme>", nme$ fstmessge$ = nme$ " s my fend." secondmessge$ = "I ke " nme$ "." nt fstmessge$ sy fstmessge$ nt secondmessge$ sy secondmessge$ Pogm 27: I Lke f n the nk ente you nme>vnce Vnce s my fend. I ke Vnce. Sme Outut 27: I Lke f n the nk 2014 Jmes M. Reneu (CC BY-NC-SA 3.0 US)
Chte 5: You Pogm Asks fo Advce. Pge 66 "omt", stngve$ "omt", numecve stngve$ numecve The sttement w eteve stng o nume tht the use tyes nto the text outut e of the sceen. The esut w e stoed n ve tht my e used te n the ogm. A omt messge, f secfed, w dsy on the text outut e nd the cuso w decty foow the omt. If numec esut s desed (numec ve secfed n the sttement) nd the use tyes stng tht cn not e conveted to nume the sttement w set the ve to zeo (0). The "Mth-wz" ogm shows n exme of wth numec ves. 1 2 3 4 5 6 7 8 9 10 11 12 # c5_mthwz.ks # show seve mthemtc oetons "? ", "? ", nt nt nt nt nt nt "" "-" "-" "*" "/" "/" () (-) (-) (*) (/) (/) Pogm 28: Mth-wz? 7? 56 2014 Jmes M. Reneu (CC BY-NC-SA 3.0 US)
Chte 5: You Pogm Asks fo Advce. Pge 67 756=63 7-56=-49 56-7=49 7*56=392 7/56=0.125 56/7=8 Sme Outut 28: Mth-wz Ths chte hs two "Bg Pogms" The fst s fncy ogm tht w sy you nme nd how od you w e n 8 yes nd the second s sy stoy geneto. 1 2 3 4 5 6 7 8 9 10 11 12 # c5_synme.ks "Wht s you nme?", nme$ "How od e you?", ge geetng$ = "It s nce to meet you, " nme$ "." nt geetng$ sy geetng$ geetng$ = "In 8 yes you w e " (ge 8) " yes od. Wow, thts od!" nt geetng$ sy geetng$ Pogm 29: Fncy Sy Nme Wht s you nme?joe 2014 Jmes M. Reneu (CC BY-NC-SA 3.0 US)
Chte 5: You Pogm Asks fo Advce. Pge 68 How od e you?13 It s nce to meet you, Joe. In 8 yes you w e 21 yes od. thts od! Wow, Sme Outut 29: Fncy Sy Nme 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 # c5_systoy.ks nt "A Sy Stoy." noun? ", noun1$ ve? ", ve1$ oom n you house? ", oom1$ ve? ", ve2$ noun? ", noun2$ n djectve? ", dj1$ ve? ", ve3$ noun? ", noun3$ You Nme? ", nme$ sentence$ = "A sy stoy, y " nme$ "." nt sentence$ sy sentence$ sentence$ = "One dy, not so ong go, I sw " noun1$ " " ve1$ " down the sts." nt sentence$ sy sentence$ sentence$ = "It ws gong to my " oom1$ " to " ve2$ " " noun2$ nt sentence$ sy sentence$ sentence$ = "The " noun1$ " ecme " dj1$ " when I " ve3$ " wth " noun3$ "." nt sentence$ 2014 Jmes M. Reneu (CC BY-NC-SA 3.0 US)
Chte 5: You Pogm Asks fo Advce. 29 30 31 32 33 Pge 69 sy sentence$ sentence$ = "The End." nt sentence$ sy sentence$ Pogm 30: Bg Pogm - Sy Stoy Geneto A Sy Stoy. Ente noun? c Ente ve? wk Ente oom n you house? ktchen Ente ve? sng Ente noun? teevson Ente n djectve? huge Ente ve? wtch Ente noun? comute Ente You Nme? Jm A sy stoy, y Jm. One dy, not so ong go, I sw c wk down the sts. It ws gong to my ktchen to sng teevson The c ecme huge when I wtch wth comute. The End. Sme Outut 30: Bg Pogm - Sy Stoy Geneto 2014 Jmes M. Reneu (CC BY-NC-SA 3.0 US)
Chte 5: You Pogm Asks fo Advce. Pge 70 Execses: e y q q t h y d s j s x w v e o t f f c e f m n y n k d g x x h u t n u z y g t g k e f v w t v x w j o z k g q z v n g s o d defut, dosgn,, omt, stng, ve 5.1. Wte ogm to sk fo thee nmes. Stoe them n stng ves. Once the use entes the thd nme hve the comute ecte the cssc ygound song usng the nmes: [Nme One] nd [Nme Two] sttng n tee, K-I-S-S-I-N-G. Fst comes ove, then comes mge, then comes [Nme Thee] n y cge! 5.2. Wte ogm to sk fo n djectve, noun, nm, nd sound. Once the use entes the st one, ud snge stng ve (usng conctenton) to sy vese of Od McDond. Pnt the esut out wth snge sttement nd sy t wth snge sttement. (Adted fom The Od Mcdond Md L fom htt://www.mdgs.com) 2014 Jmes M. Reneu (CC BY-NC-SA 3.0 US)
Chte 5: You Pogm Asks fo Advce. Pge 71 [Adjectve] McDond hd [Noun], E-I-E-I-O nd on tht [Noun] he hd n nm, E-I-E-I-O wth [Sound] [Sound] hee nd [Sound] [Sound] thee, hee [Sound], thee [Sound], eveywhee [Sound] [Sound], [Adjectve] McDond hd [Noun], E-I-E-I-O. 2014 Jmes M. Reneu (CC BY-NC-SA 3.0 US)
Chte 5: You Pogm Asks fo Advce. Pge 72 2014 Jmes M. Reneu (CC BY-NC-SA 3.0 US)