How to resolve the algorithm Magic 8-ball step by step in the BASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Magic 8-ball step by step in the BASIC programming language

Table of Contents

Problem Statement

Create Magic 8-Ball.

See details at:   Magic 8-Ball.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Magic 8-ball step by step in the BASIC programming language

Source code in the basic programming language

dim answer$(20)
answer$[0] = "It is certain."
answer$[1] = "It is decidedly so."
answer$[2] = "Without a doubt."
answer$[3] = "Yes - definitely."
answer$[4] = "You may rely on it."
answer$[5] = "As I see it, yes."
answer$[6] = "Most likely."
answer$[7] = "Outlook good."
answer$[8] = "Yes."
answer$[9] = "Signs point to yes."
answer$[10] = "Reply hazy, try again."
answer$[11] = "Ask again later."
answer$[12] = "Better not tell you now."
answer$[13] = "Cannot predict now."
answer$[14] = "Concentrate and ask again."
answer$[15] = "Don't count on it."
answer$[16] = "My reply is no."
answer$[17] = "My sources say no."
answer$[18] = "Outlook not so good."
answer$[19] = "Very doubtful."

print "Q to quit."
while True
	input string "What would you like to know? ", question$
	if upper(question$) = "Q" then exit while
	print answer$[int(rand * answer$[?])]
	print
end while
end

100 cls
110 data "It is certain.","It is decidedly so."
120 data "Without a doubt.","Yes - definitely."
130 data "You may rely on it.","As I see it, yes."
140 data "Most likely.","Outlook good."
150 data "Yes.","Signs point to yes."
160 data "Reply hazy, try again.","Ask again later."
170 data "Better not tell you now.","Cannot predict now."
180 data "Concentrate and ask again.","Don't count on it."
190 data "My reply is no.","My sources say no."
200 data "Outlook not so good.","Very doubtful."
210 dim m8ball$(20)
220 for i = 0 to 19
230   read m8ball$(i)
240 next i
250 randomize timer
260 input "What would you like to know? ",q$
270 print m8ball$(int(rnd(20)))
280 end


100 PROGRAM "Magic8.bas"
110 RANDOMIZE 
120 STRING ANSWER$(1 TO 20)*26
130 FOR I=1 TO 20
140   READ ANSWER$(I)
150 NEXT 
160 CLEAR SCREEN
170 PRINT "Magic 8-ball":PRINT "Q to quit.":PRINT 
180 DO 
190   INPUT PROMPT "What would you like to know? ":QUESTION$
200   IF LCASE$(QUESTION$)="q" THEN EXIT DO
210   PRINT ANSWER$(RND(20)+1):PRINT 
220 LOOP 
230 DATA It is certain.,It is decidedly so.,Without a doubt.
240 DATA Yes - definitely.,You may rely on it.,"As I see it, yes."
250 DATA Most likely.,Outlook good.,Yes.
260 DATA Signs point to yes.,"Reply hazy, try again.",Ask again later.
270 DATA Better not tell you now.,Cannot predict now.,Concentrate and ask again.
280 DATA Don't count on it.,My reply is no.,My sources say no.
290 DATA Outlook not so good.,Very doubtful.

100 CLS
110 DATA "It is certain.","It is decidedly so."
120 DATA "Without a doubt.","Yes - definitely."
130 DATA "You may rely on it.","As I see it, yes."
140 DATA "Most likely.","Outlook good."
150 DATA "Yes.","Signs point to yes."
160 DATA "Reply hazy, try again.","Ask again later."
170 DATA "Better not tell you now.","Cannot predict now."
180 DATA "Concentrate and ask again.","Don't count on it."
190 DATA "My reply is no.","My sources say no."
200 DATA "Outlook not so good.","Very doubtful."
210 DIM m$(20)
220 FOR i = 0 TO 19
230   READ m$(i)
240 NEXT i
260 INPUT "What would you like to know? "; q$
270 PRINT m$(INT(RND(20)))
280 END


DIM answer$(19)
FOR i = 0 TO UBOUND(answer$): READ answer$(i): NEXT i
RANDOMIZE TIMER

PRINT "Q to quit."
DO
    INPUT "What would you like to know? ", question$
    IF UCASE$(question$) = "Q" THEN EXIT DO
    PRINT answer$(INT(RND * UBOUND(answer$)))
    PRINT
LOOP
END

DATA "It is certain.","It is decidedly so."
DATA "Without a doubt.","Yes – definitely."
DATA "You may rely on it.","As I see it, yes."
DATA "Most likely.","Outlook good.","Yes."
DATA "Signs point to yes.","Reply hazy, try again."
DATA "Ask again later.","Better not tell you now."
DATA "Cannot predict now.","Concentrate and ask again."
DATA "Don't count on it.","My reply is no."
DATA "My sources say no.","Outlook not so good."
DATA "Very doubtful."


DIM answer$(20)
FOR i = 1 to ubound(answer$)
    READ answer$(i)
NEXT i
DATA "It is certain.", "It is decidedly so."
DATA "Without a doubt.", "Yes – definitely."
DATA "You may rely on it.", "As I see it, yes."
DATA "Most likely.", "Outlook good.", "Yes."
DATA "Signs point to yes.", "Reply hazy, try again."
DATA "Ask again later.", "Better not tell you now."
DATA "Cannot predict now.", "Concentrate and ask again."
DATA "Don't count on it.", "My reply is no."
DATA "My sources say no.", "Outlook not so good."
DATA "Very doubtful."

RANDOMIZE
PRINT "Q to quit."
DO
   INPUT prompt "What would you like to know? ": question$
   IF ucase$(question$) = "Q" then EXIT DO
   PRINT answer$(int(rnd*ubound(answer$)))
   PRINT
LOOP
END


dim answer$(19)
for i = 0 to arraysize(answer$(),1): read answer$(i): next i

print "Q to quit."
do
    input "What would you like to know? " question$
    if upper$(question$) = "Q" then end : fi
    print answer$(int(ran(arraysize(answer$(),1))))
    print
loop

data "It is certain.","It is decidedly so."
data "Without a doubt.","Yes – definitely."
data "You may rely on it.","As I see it, yes."
data "Most likely.","Outlook good.","Yes."
data "Signs point to yes.","Reply hazy, try again."
data "Ask again later.","Better not tell you now."
data "Cannot predict now.","Concentrate and ask again."
data "Don//t count on it.","My reply is no."
data "My sources say no.","Outlook not so good."
data "Very doubtful."

  

You may also check:How to resolve the algorithm Disarium numbers step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Sort three variables step by step in the COBOL programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the ColdFusion programming language
You may also check:How to resolve the algorithm Arbitrary-precision integers (included) step by step in the MATLAB programming language
You may also check:How to resolve the algorithm Hello world/Newbie step by step in the Nemerle programming language