Menu: Difference between revisions

Content added Content deleted
(add gwbasic)
(Added solution for Action!)
Line 53: Line 53:
Which is from the three pigs: 2
Which is from the three pigs: 2
You chose: huff and puff
You chose: huff and puff
</pre>

=={{header|Action!}}==
<lang Action!>DEFINE PTR="CARD"

BYTE FUNC Init(PTR ARRAY items)
items(0)="fee fie"
items(1)="huff and puff"
items(2)="mirror mirror"
items(3)="tick tock"
RETURN (4)

PROC ShowMenu(PTR ARRAY items BYTE count)
BYTE i
FOR i=1 TO count
DO
PrintF("(%B) %S%E",i,items(i-1))
OD
RETURN

BYTE FUNC GetMenuItem(PTR ARRAY items BYTE count)
BYTE res
DO
ShowMenu(items,count) PutE()
Print("Make your choise: ")
res=InputB()
UNTIL res>=1 AND res<=count
OD
RETURN (res-1)

PROC Main()
PTR ARRAY items(10)
BYTE count,res

count=Init(items)
res=GetMenuItem(items,count)
PrintF("You have chosen: %S%E",items(res))
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Menu.png Screenshot from Atari 8-bit computer]
<pre>
(1) fee fie
(2) huff and puff
(3) mirror mirror
(4) tick tock

Make your choise: 5
(1) fee fie
(2) huff and puff
(3) mirror mirror
(4) tick tock

Make your choise: 2
You have chosen: huff and puff
</pre>
</pre>