duuude
04-05-2010, 07:01 PM
It seems like fun from what I've seen.. Has anyone ever used this??
Is this an effective and easy way to learn BASIC?
hazmat
04-05-2010, 10:18 PM
I've been taking comp sci 101 and the professor has us use Just BASIC which is the freebie version of Liberty BASIC. Its my first look into the world of programming and I'm having a lot of fun with it. There are a bunch of tutorials included with Just BASIC where you can learn pretty much everything a class would cover.
Heres some code to look at if you are curious. Its a pretty simple math problem generator, it was the 2nd homework assignment we had. The homework only required multiplication problems but i used a few tricks to get addition and subtraction in there, and statistics for extra credit. I've learned a lot since this assignment, but its fun to look at because of how I would do things differently now that I know proper branching.
'hazmat-comp sci 101
'Homework 2 - multiplication problems
do 'starts the main loop
do 'starts the problem type input loop
input "Choose a problem type ( +, -, or X): "; type$ 'assign the problem type
loop until type$="+" or type$="-" or upper$(type$)="X" 'restrict input of question types
do 'starts the number of problems input loop
input "How many problems would you like? "; prb 'assign number of questions to prb variable
loop until prb > 0 'input loops until number entered is >0
do
input "Choose the max value the problem terms: "; max
loop until max > 0
[goagain] 'marker for goagain with same settings
cls
tries = 0 'set tries counter to zero at the begining of each round
starttime = time$("ms") 'creates a timestamp (in milliseconds) before the problem loop
for prbloop = 1 to prb 'starts the problem generator loop for the entered amount of problems
term1 = int(rnd(0)*max) 'generate the first term of the, in an integer between 0 and the max term value chosen above
term2 = int(rnd(0)*max) 'generate the second term of the problem
if type$="+" then ans=term1+term2
if type$="-" then ans=term1-term2
if upper$(type$)="X" then ans=term1*term2
ansinput = .1 'reset user input before each question,
'to prevent the previous input from correctly answering the next prb
'.1 is used because a decimal isnt a possible ans when add/sub/mult'ing integers
while ans<>ansinput 'loops the problem until its answered correctly
print term1;" "; upper$(type$);" "; term2; " = "; 'print the 2 terms in the specified problem format
input "? ";ansinput 'user inputs their answer, ";" at the end of last line causes the input to print at the end of the problem
tries = tries + 1 'tries counter keeps track when the loop passes this line each time an answer is entered, for statistics
wend
print "Correctamundo!" 'acknowledge correct answer before proceeding in the loop
print
next prbloop 'loops back to the start of the problem generator
endtime = time$("ms") 'creates a timestamp at the end of the questions
if endtime < starttime then 'in the event that the ending time is less than the start time (starting before midnight and ending after)
totaltime =((86400000-starttime)+endtime)/1000 'we must calculate the difference here: number of ms in a day minus the start time yields the
else 'time between start and midnight, and we add the end time (ms after midnight) to that to get total time (divided by 1000 since its in ms)
totaltime = (endtime - starttime)/1000 'in normal circumstances the endtime will be greater than the starttime so we can just calculate the total time
end if 'by subtracting the second timestamp from the first, and the dividing by 1000 since its in milliseconds
'prepare statistics:
acc = (prb / tries)*100 'accuracy is number of problems divided by number of tries from the counter, times 100 to get a percentage
avgtime = totaltime/prb 'average time per question is totaltime divided by the number of problems
print
print "Good job there buddy!" 'congratulate user when they complete their problems
print
print "Statistics:" 'now we print up the statistics, rounding the accuracy percentage to one decimal
print
print "Problems: "; prb; " Guesses: "; tries;
print " Accuracy: "; using("###.#", acc);"%"
print "Completed in:"; using("####.#", totaltime); " seconds -";
print " Averaging"; using("###.#",avgtime); " seconds per question"
print
do 'start input loop for go again
input "Go again? y/n "; again$
loop until upper$(again$)="Y" or upper$(again$)="N" 'input loop only exits when "go again" is a y or n
if upper$(again$)="Y" then goto [samesettings]
if upper$(again$)="N" then goto [ending]
[samesettings]
do
input "With same settings? y/n "; same$
loop until upper$(same$)="Y" or upper$(same$)="N"
if upper$(same$)="Y" then goto [goagain]
cls
[ending]
loop until upper$(again$)="N"
cls
print "Thanks for playing!" 'thank the user when they're done
end
vBulletin® v3.8.1, Copyright ©2000-2013, Jelsoft Enterprises Ltd.