Script won't print any result

  1. What do you want to achieve?
    I want to make a script that solves a quadratic equation
  2. What is the issue?
    The issue is that my script won’t print any result
a = 12   
b = 8
c = 71

d = (b^2) - (4*a*c) 

while d >= 0 do -- Checking if the Discriminant is either positive or equal to 0
	if d > 0 then do -- if the Discriminant is positive 
			result1 = (-b + math.sqrt(d) / (2*a))
			result2 = (-b - math.sqrt(d) / (2*a))
			print(result1)
			print(result2)
		end
	elseif d == 0 then -- else if the Discriminant is equal to 0
		result3 = - (b / (2 * a))
		print(result3)
	end
end

  1. What solutions have you tried so far?
    Many but I have not found what is the problem yet. Help would really be really appreciated! Thanks in advance.

That would be because b = -3344

2 Likes

Yeah, So the loop never even runs in the first place so it couldn’t possibly print anything

1 Like

It does print a result when I fix the numbers but the loop does indeed not run well.
image

1 Like

Finally fixed it!

a = 12
b = 8
c = 1

d = (b^2) - (4*a*c)

if (d >0) then
	result1 = (-b + math.sqrt(d) / (2*a))
	result2 = (-b - math.sqrt(d) / (2*a))
	print(result1)
	print(result2)
elseif (d==0) then
	result3 = - (b / (2 * a))
	print(result3)
elseif (d<0) then
	print("Can't solve this one")
end

Thanks Kaid3n22 and jsnotlout1 for the help!

1 Like