The Name Game: Difference between revisions

Added Commodore BASIC
mNo edit summary
(Added Commodore BASIC)
Line 219:
 
</pre>
 
=={{header|Commodore BASIC}}==
 
This should be adaptable to most other 8-bit BASICs. After looking at some of the other examples, this example decides to tackle the task of checking for consonant blends (''th'', ''fr'', ''sh'', ''ch'', ''chr'', etc.) at the start of the name and handle it appropriately.
 
Note also the code on lines 30 and 75 to convert the case of the first letter... On some Commodore machines, the default is to render text in ALL CAPS, shifted letters become graphic symbols. This program sets the mode to display mixed case [chr$(14)] and then converts the first letter of the name for the purpose of uniform pattern matching in case the user types the name properly with a capitalized first letter.
 
<lang gwbasic>1 rem name game
2 rem rosetta code
5 dim cn$(3),bl$(3,32):gosub 1000
 
10 print chr$(147);chr$(14);"Name Game":print
15 cn$(0)="":cn$(1)="b":cn$(2)="f":cn$(3)="m"
20 print chr$(147);chr$(14);"Name Game":print:input "Enter any name";n$
25 rem ensure first letter is lowercase
30 n$=chr$(asc(n$) and 95)+right$(n$,len(n$)-1)
35 rem check vowels
40 v$="aeiou":i$=left$(n$,1):v=0
45 for i=1 to 5:v=i$=mid$(v$,i,1):if not v then next i
50 if v then tn$=n$:goto 70
55 gosub 500
60 if bl then goto 70
65 tn$=right$(n$,len(n$)-1):gosub 600
70 rem capitalize first letter in name
75 n$=chr$(asc(n$) or 128)+right$(n$,len(n$)-1)
80 gosub 700
83 print:print "Again? (Y/N)"
85 get k$:if k$<>"y" and k$<>"n" then 85
90 if k$="y" then goto 10
95 end
 
500 rem check blends
510 bl=0:for g=3 to 1 step -1
520 l$=left$(n$,g+1):tn$=right$(n$,len(n$)-(g+1))
530 for i=1 to 32:if l$=bl$(g,i) then bl=-1:return
540 next i:next g
550 return
 
600 rem check b, f, and m
610 for i=1 to 3:if cn$(i)=chr$(asc(n$)) then cn$(i)=""
620 next i:return
 
700 rem sing the verse
710 print:print n$;", ";n$;", bo-";cn$(1);tn$
720 print " Banana-fana fo-";cn$(2);tn$
730 print " Fee-fi-mo-";cn$(3);tn$
740 print n$;"!"
750 return
 
1000 rem load blends
1010 for g=1 to 3
1015 for i=1 to 32
1020 read bl$(g,i):if bl$(g,i)="xx" then next g:return
1030 next i
 
2000 rem digraphs
2005 data bl,br,ch,ck,cl,cr,dr,fl,fr,gh,gl,gr,ng
2010 data ph,pl,pr,qu,sc,sh,sk,sl,sm,sn,sp,st,sw
2020 data th,tr,tw,wh,wr
2029 data xx
2030 rem trigraphs
2040 data chr,sch,scr,shr,spl,spr,squ,str,thr
2049 data xx
2050 rem quadgraph
2060 data schr,schl
2069 data xx</lang>
 
{{out}}
<pre>
Name Game
 
Enter a name? Gary
 
Gary, Gary, bo-bary
Banana-fana fo-fary
Fee-fi-mo-mary
Gary!
 
Again? (Y/N) Y
 
Name Game
 
Enter a name? Steve
 
Steve, Steve, bo-beve
Banana-fana fo-feve
Fee-fi-mo-meve
Steve!
 
Again? (Y/N) Y
 
Name Game
 
Enter a name? Erik
 
Erik, Erik, bo-berik
Banana-fana fo-ferik
Fee-fi-mo-merik
Erik!
 
Again? (Y/N) Y
 
Enter a name? Charlie
 
Charlie, Charlie, bo-barlie
Banana-fana fo-farlie
Fee-fi-mo-marlie
Charlie!
 
Again? (Y/N) Y
 
Name Game
 
Enter a name? Matthew
 
Matthew, Matthew, bo-batthew
Banana-fana fo-fatthew
Fee-fi-mo-atthew
Matthew!
 
Again? (Y/N) N
 
ready.
</pre>
 
=={{header|C}}==
{{trans|Kotlin}}
113

edits