I need to find the square roots of a quadratic equation: ax^2+bx+c=0.
let h a b c =
if (b*b-4*a*c) < 0 then begin
print_string "There are no real solutions"
end
else if (b*b-4*a*c) = 0 then begin
print_string "The equation has 1 solution x_1=";
print_int ((-b)/(2*a));
end
else begin
float_of_int a;
float_of_int b;
float_of_int c;
print_float (((-.b)+.sqrt(b*.b-.4.*.a*.c))/.(2.*.a));
print_float (((-.b)-.sqrt(b*.b-.4.*.a*.c))/.(2.*.a))
end;;
Why this code gives me syntax error here saying that "This expression has type int but an expression was expected of type float":
begin
float_of_int a;
float_of_int b;
float_of_int c;
print_float (((-.b)+.sqrt(b*.b-.4.*.a*.c))/.(2.*.a));
print_float (((-.b)-.sqrt(b*.b-.4.*.a*.c))/.(2.*.a))
end;;
Also is there any other easier way to solve this problem?