none
Beginner wanting help with ideas for projects. RRS feed

  • Question

  • Hi guys, I'm a 17 year-old who has been coding websites since the age of 11, I am proficient with XHTML, CSS and some Javascript; I've decided that I'd like to try my hand at programing and a friend suggested that I start with Small Basic.

    I would really like to make some mathematical calculators using Small Basic, I would especially like to make some involving the following formulae:

    • Volume of a Sphere
    • Quadratic Equation
    • Kinetic Energy

    If you could be kind enough to point me to the tutorial(s) from which I can acquire the knowledge to do this I would be very greatfull. 

    Ok, I've managed to do the volume of a sphere and kinetic energy, but need help with Quadratic Equation solver...

    • Edited by Sam .223 Saturday, September 25, 2010 7:10 PM
    Saturday, September 25, 2010 10:45 AM

Answers

  • Quadratic Equation Solver:

    TextWindow.WriteLine("The equation is a^2*x + b*x + c = 0.")
    
    TextWindow.Write("Type A: ")
    ANumber = TextWindow.ReadNumber()
    
    TextWindow.Write("Type B: ")
    BNumber = TextWindow.ReadNumber()
    
    TextWindow.Write("Type C: ")
    CNumber = TextWindow.ReadNumber()
    
    TextWindow.WriteLine("Please wait... Counting.")
    
    Delta = BNumber * BNumber - (4 * ANumber * CNumber)
    
    If Delta < 0 Then
            TextWindow.WriteLine("ERROR: THERE ARE NO X's THAT SOLVE EQUATION.")
    Else
            If Delta = 0 Then
                     DeltaSqrt = Math.SquareRoot(Delta)
                     X = ( -BNumber + DeltaSqrt) / (2 * ANumber)
                     TextWindow.WriteLine("X: " + X)
            Else
                     X1 = ( -BNumber + DeltaSqrt) / (2 * ANumber)
                     X2 = ( -BNumber - DeltaSqrt) / (2 * ANumber)
                     TextWindow.WriteLine("X1: " + X1)
                     TextWindow.WriteLine("X1: " + X1)
            EndIf
    EndIf
    
    
    
    

    • Marked as answer by Sam .223 Saturday, September 25, 2010 7:30 PM
    Saturday, September 25, 2010 7:29 PM
  • I'M WORKING SO HARD: MARK ME AS ANSWER.

    The GoodMorning program:

    If Clock.Hour < 6 Then
    TimeOfDayText = "It's night! Why aren't You sleeping?"
    EndIf
    
    If Clock.Hour >= 6 And Clock.Hour < 12 Then
    TimeOfDayText = "Good Morning!"
    EndIf
    
    If Clock.Hour >= 12 And Clock.Hour < 18 Then
    TimeOfDayText = "Good Afternoon!"
    EndIf
    
    If Clock.Hour >= 18 And Clock.Hour < 22 Then
    TimeOfDayText = "Good Evening!"
    EndIf
    
    If Clock.Hour >= 22 And Clock.Hour < 24 Then
    TimeOfDayText = "Go To Bed!!!!!!"
    EndIf
    
    'CHECK THE Clock.Hour property in action (I don't have Small Basic running now, so I can't really test it).
    
    GraphicsWindow.ShowMessage("Thanks for running my app.", TimeOfDayText)

    • Proposed as answer by Jacob Brown Saturday, September 25, 2010 7:48 PM
    • Marked as answer by Sam .223 Saturday, September 25, 2010 8:08 PM
    Saturday, September 25, 2010 7:38 PM
  • Try this:

    ContinueCalculations = "True"
    
    While ContinueCalculation = "True"
    
    
    
    
    
    ''' TO DO: PERFORM CALCULATIONS CODE HERE
    
    
    
    
    
    
    ''' ASK THE USER IF HE/SHE WANTS TO DO MORE:
    TextWindow.Write("Perform another calculation: (Y/N)")
    CCAnswer = TextWindow.Read()
    If CCAnswer = "N" Then
       ContinueCalculations = "False"
    EndIf
    EndWhile
    
    '''' TO DO: INSERT ACTIONS TO DO AFTER PERFORMING ALL THE CALCULATION, for example: thank the user for using Your app
    

    • Proposed as answer by Jacob Brown Saturday, September 25, 2010 7:48 PM
    • Marked as answer by Sam .223 Saturday, September 25, 2010 8:09 PM
    Saturday, September 25, 2010 7:45 PM
  • TextWindow.WriteLine("X" + Text.GetCharacter(178))
    '0r
    TextWindow.WriteLine("X²")
    Sorry My Bad English
    • Marked as answer by Sam .223 Saturday, October 2, 2010 12:40 PM
    Monday, September 27, 2010 4:31 PM

All replies

  • This is a SMALL BASIC forum, and Small Basic is something totally different then Visual Basic. For more info on Visual Basic visit: http://msdn.microsoft.com/en-us/vbasic/ms789086.aspx.

    Small Basic is a simplified version for educational purposes. For more info visit: http://smallbasic.com/

    If You would be interested in Small Basic, take a look at:

     

    Type "Small Basic" in Google for more.
    Saturday, September 25, 2010 7:08 PM
  • Sorry, that was a typo I meant Small Basic! 
    Saturday, September 25, 2010 7:10 PM
  • If You are in Small Basic (not in Visual Basic) then:

     

    TextWindow.Write("Speed: ")
    
    speed = TextWindow.ReadNumber()
    
    TextWindow.Write("Mass: ")
    
    mass = TextWindow.ReadNumber()
    
    kineticEnergy = speed * speed * mass / 2
    
    TextWindow.WriteLine("Kinetic Energy: " + kineticEnergy + ".")
    
    
    

     

    • Proposed as answer by Jacob Brown Saturday, September 25, 2010 7:17 PM
    Saturday, September 25, 2010 7:14 PM
  • I'm getting points on this forum, so if You could be so kind and mark me as answer.

    Thanks.

    Saturday, September 25, 2010 7:15 PM
  • Sorry, mate, I'm new here and wasn't aware of that feature... I only need help with the Quadratic Equation Solver now, I want it to be able to solve any Quadratic Equation (including: negative numbers, surds, multiples, etc...) 
    Saturday, September 25, 2010 7:17 PM
  • Wait a moment... I'm typing.

    By the time click "Mark as answer" please.

    Saturday, September 25, 2010 7:19 PM
  • Of course mate, I'm afraid I have another question: Is it possible to request a password? Oh and I'd like to be able to say "Good x" depending on the time of day, morning, afternoon or evening. :) 

    The way you made your kinetic energy calculator is much more elegant than mine - thank you very much for your insight. How do I display powers in .Write("")? like x²?

    Saturday, September 25, 2010 7:22 PM
  • Quadratic Equation Solver:

    TextWindow.WriteLine("The equation is a^2*x + b*x + c = 0.")
    
    TextWindow.Write("Type A: ")
    ANumber = TextWindow.ReadNumber()
    
    TextWindow.Write("Type B: ")
    BNumber = TextWindow.ReadNumber()
    
    TextWindow.Write("Type C: ")
    CNumber = TextWindow.ReadNumber()
    
    TextWindow.WriteLine("Please wait... Counting.")
    
    Delta = BNumber * BNumber - (4 * ANumber * CNumber)
    
    If Delta < 0 Then
            TextWindow.WriteLine("ERROR: THERE ARE NO X's THAT SOLVE EQUATION.")
    Else
            If Delta = 0 Then
                     DeltaSqrt = Math.SquareRoot(Delta)
                     X = ( -BNumber + DeltaSqrt) / (2 * ANumber)
                     TextWindow.WriteLine("X: " + X)
            Else
                     X1 = ( -BNumber + DeltaSqrt) / (2 * ANumber)
                     X2 = ( -BNumber - DeltaSqrt) / (2 * ANumber)
                     TextWindow.WriteLine("X1: " + X1)
                     TextWindow.WriteLine("X1: " + X1)
            EndIf
    EndIf
    
    
    
    

    • Marked as answer by Sam .223 Saturday, September 25, 2010 7:30 PM
    Saturday, September 25, 2010 7:29 PM
  • Thank you very much for helping me so much. Could you provide an If statement that allows the user to choose whether they want to make another calculation (which displays directly below the first one,) or simply says "Thank you for using my program!"
    Saturday, September 25, 2010 7:32 PM
  • I'M WORKING SO HARD: MARK ME AS ANSWER.

    The GoodMorning program:

    If Clock.Hour < 6 Then
    TimeOfDayText = "It's night! Why aren't You sleeping?"
    EndIf
    
    If Clock.Hour >= 6 And Clock.Hour < 12 Then
    TimeOfDayText = "Good Morning!"
    EndIf
    
    If Clock.Hour >= 12 And Clock.Hour < 18 Then
    TimeOfDayText = "Good Afternoon!"
    EndIf
    
    If Clock.Hour >= 18 And Clock.Hour < 22 Then
    TimeOfDayText = "Good Evening!"
    EndIf
    
    If Clock.Hour >= 22 And Clock.Hour < 24 Then
    TimeOfDayText = "Go To Bed!!!!!!"
    EndIf
    
    'CHECK THE Clock.Hour property in action (I don't have Small Basic running now, so I can't really test it).
    
    GraphicsWindow.ShowMessage("Thanks for running my app.", TimeOfDayText)

    • Proposed as answer by Jacob Brown Saturday, September 25, 2010 7:48 PM
    • Marked as answer by Sam .223 Saturday, September 25, 2010 8:08 PM
    Saturday, September 25, 2010 7:38 PM
  • Try this:

    ContinueCalculations = "True"
    
    While ContinueCalculation = "True"
    
    
    
    
    
    ''' TO DO: PERFORM CALCULATIONS CODE HERE
    
    
    
    
    
    
    ''' ASK THE USER IF HE/SHE WANTS TO DO MORE:
    TextWindow.Write("Perform another calculation: (Y/N)")
    CCAnswer = TextWindow.Read()
    If CCAnswer = "N" Then
       ContinueCalculations = "False"
    EndIf
    EndWhile
    
    '''' TO DO: INSERT ACTIONS TO DO AFTER PERFORMING ALL THE CALCULATION, for example: thank the user for using Your app
    

    • Proposed as answer by Jacob Brown Saturday, September 25, 2010 7:48 PM
    • Marked as answer by Sam .223 Saturday, September 25, 2010 8:09 PM
    Saturday, September 25, 2010 7:45 PM
  • If You could, mark this post as answer, too. :-)
    Saturday, September 25, 2010 7:46 PM
  • This doesn't give correct answers... for example try, A:1 B:-3 C:-4 the correct answer is x= 4 0r -1 not -1.5. Unfortunately I cannot see where you have gone wrong... 
    Saturday, September 25, 2010 8:34 PM
  • If you  want write something like x² use

    TextWindow.Write("Please Enter Base Number ")
    X = TextWindow.ReadNumber()
    TextWindow.WriteLine(Math.Power(X,2))

    Sorry My Bad English
    Saturday, September 25, 2010 8:43 PM
  • I meant how do I display TextWindow.Writeline("x²") so it literally displays: 'x²'
    Saturday, September 25, 2010 8:46 PM
  • Try this:

    Text.GetCharacter(code)

    where code is ASCII code number for the ² symbol. I don't have to possibility to find out that number now.

    Monday, September 27, 2010 4:00 PM
  • TextWindow.WriteLine("X" + Text.GetCharacter(178))
    '0r
    TextWindow.WriteLine("X²")
    Sorry My Bad English
    • Marked as answer by Sam .223 Saturday, October 2, 2010 12:40 PM
    Monday, September 27, 2010 4:31 PM
  • A good way to learn is to convert a project from another similar language. Check out the online copies of these books:

    Games in Basic: http://www.atariarchives.org/basicgames/

    and

    More Games in Basic: http://www.atariarchives.org/morebasicgames/

    The games described are written in the old MS Basic interpreter from the late 70's and early 80's. The code is really horrible examples of proper programming practices, but getting them to work should give you a nice low level challenge.

    And there is nothing more entertaining then working with game logic.

    Good luck.

    Saturday, October 9, 2010 10:41 PM
    Answerer