Project: Quadratic Roots
Quadratic equations of the form Ax2 + Bx + C = 0 have two possible solutions given by the [[Quadratic Formula]]. Write a program that sets the constants A = 2, B = 4 and C = 1 then prints the two possible solutions. Then change the constants A, B and C to get solutions to other quadratic equations. Is it possible that this program could fail?
Output
$ rustc QuadraticRoots.rs
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
--> QuadraticRoots.rs:13:39
|
13 | let mut discriminant:f64 = B * B - 4.f64 * A * C;
| ^^^
|
help: if intended to be a floating point literal, consider adding a `0` after the period
|
13 | let mut discriminant:f64 = B * B - 4.0f64 * A * C;
| +
error[E0425]: cannot find function `sqrt` in this scope
--> QuadraticRoots.rs:14:17
|
14 | discriminant = sqrt(discriminant);
| ^^^^ not found in this scope
|
help: use the `.` operator to call the method `sqrt` on `f64`
|
14 - discriminant = sqrt(discriminant);
14 + discriminant = discriminant.sqrt();
|
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
--> QuadraticRoots.rs:15:47
|
15 | let mut root1:f64 = (-B + discriminant) / (2.f64 * A);
| ^^^
|
help: if intended to be a floating point literal, consider adding a `0` after the period
|
15 | let mut root1:f64 = (-B + discriminant) / (2.0f64 * A);
| +
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
--> QuadraticRoots.rs:16:47
|
16 | let mut root2:f64 = (-B - discriminant) / (2.f64 * A);
| ^^^
|
help: if intended to be a floating point literal, consider adding a `0` after the period
|
16 | let mut root2:f64 = (-B - discriminant) / (2.0f64 * A);
| +
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0425, E0610.
For more information about an error, try `rustc --explain E0425`.