Resolver ecuaciones cuadráticas. ax ² + bx + c = 0 (código Small. Basic)

cuadrática1


Small Basic   by Sam Christy
………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………..
TextWindow.Title=”Quadratic Equation Solver© – Brought to you by Sam Christy”
TextWindow.BackgroundColor = “Yellow”
TextWindow.ForegroundColor=”Black “
TextWindow.WriteLine(“ax² + bx + c = 0″)
start:
TextWindow.WriteLine(“”)
TextWindow.Write(“a: “)
a=TextWindow.ReadNumber()
If a = 0 Then
TextWindow.WriteLine(“”)
TextWindow.WriteLine(“ERROR: Equation invalid, a = “+a+”, a cannot = 0.”)
TextWindow.WriteLine(“Please try again…”)
TextWindow.PauseWithoutMessage()
Goto start
EndIf
TextWindow.Write(“b: “)
b=TextWindow.ReadNumber()
TextWindow.Write(“c: “)
c=TextWindow.ReadNumber()
TextWindow.WriteLine(“”)
TextWindow.WriteLine(“Equation: “+a+”x² + “+b+”x + “+c+” = 0″)
TextWindow.WriteLine(“”)
delta=Math.Power(b,2)-4*a*c
If delta < 0 Then
TextWindow.WriteLine(“ERROR: Equation invalid, Delta (b² – 4ac) = “+delta+”, Delta cannot be less than 0.”)
TextWindow.WriteLine(“Please try again…”)
TextWindow.PauseWithoutMessage()
Goto start
Else
If delta = 0 Then
solution1 =(-b+Math.SquareRoot(Math.Power(b,2)-4*a*c))/(2*a)
TextWindow.WriteLine(“x: ” + solution1)
Else
solution1 =(-b+Math.SquareRoot(Math.Power(b,2)-4*a*c))/(2*a)
solution2 =(-b-Math.SquareRoot(Math.Power(b,2)-4*a*C))/(2*a)
TextWindow.WriteLine(“x: ” + solution1)
TextWindow.WriteLine(“x: ” + solution2)
EndIf
EndIf
TextWindow.WriteLine(“”)
TextWindow.WriteLine(“Would you like to perform another calculation? (Y or N)”)
answer=TextWindow.Read()
If answer = “Y” Or answer = “y” Then
Goto start
Else
TextWindow.Clear()
TextWindow.WriteLine(“I hope you have enjoyed using my program!”)
TextWindow.WriteLine(“©Copyright Sam Christy 2010″)
TextWindow.WriteLine(“”)
TextWindow.WriteLine(“Simply press any key to exit…”)
TextWindow.PauseWithoutMessage()
Program.End()
EndIf

Deja un comentario