Zoklet.net

Go Back   Zoklet.net > Technology > Technophiles and Technophiliacs > Codes of all kinds

Reply
 
Thread Tools
  #1  
Old 04-05-2010, 07:01 PM
duuude duuude is offline
New Arrival
 
Join Date: Jan 2009
Thanks: 27
Thanked 12 Times in 11 Posts
Default Liberty BASIC

It seems like fun from what I've seen.. Has anyone ever used this??
Is this an effective and easy way to learn BASIC?
Reply With Quote
  #2  
Old 04-05-2010, 10:18 PM
hazmat hazmat is offline
Regular
 
Join Date: Feb 2009
Thanks: 8
Thanked 45 Times in 37 Posts
Default Re: Liberty BASIC

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.
Code:
'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

Last edited by hazmat; 04-06-2010 at 09:49 AM.
Reply With Quote
The following users say "It is so good to hear it!":
duuude (04-06-2010)
Reply

Bookmarks

Tags
basic, liberty

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
GTA: Episodes from Liberty City versus GTA4 Dog Fragyard 7 01-30-2010 04:22 PM
GTA: Episodes from Liberty City Dog Fragyard 5 01-14-2010 11:42 AM
Is learning basic piano as easy as learning basic guitar? BlackSails The Musician's Playground 47 11-25-2009 01:23 AM
GTA: Episodes from Liberty City Hamza Fragyard 11 10-31-2009 06:47 PM
Funding Liberty Reserve h0ppinlowrider Graduation to Obligation 3 01-31-2009 07:24 PM


All times are GMT. The time now is 12:24 PM.


Hot Topics
On IRC
Users: 4
Messages/minute: 0
Topic: "http://www.zoklet.net/..."
Users: 17
Messages/minute: 0
Topic: "dangly parts"
Users: 8
Messages/minute: 0
Topic: "vaginaboob"
Advertisements
Your ad could go right HERE! Contact us!

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.