Pure Programmer
Blue Matrix


Cluster Map

Project: Quadratic Roots (Command Line)

Quadratic equations of the form Ax2 + Bx + C = 0 have two possible solutions given by the [[Quadratic Formula]]. Write a program that prints the two possible roots of a quadratic equation. Then values A, B and C should be passed in on the command line.

See: QuadraticRoots

Output
$ rustc QuadraticRootsCmdLine.rs error: unknown format trait `s` --> QuadraticRootsCmdLine.rs:12:38 | 12 | println!("{}", format!("Syntax: {0:s} a b c", utils::program_name().expect("program name should not be empty!"))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error[E0425]: cannot find value `args` in this scope --> QuadraticRootsCmdLine.rs:11:5 | 11 | if args.len() != 4 { | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> QuadraticRootsCmdLine.rs:13:3 | 13 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::process::exit; | error[E0425]: cannot find value `Utils` in this scope --> QuadraticRootsCmdLine.rs:15:14 | 15 | let A:f64 = Utils.stodWithDefault(args[1], 0); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> QuadraticRootsCmdLine.rs:15:36 | 15 | let A:f64 = Utils.stodWithDefault(args[1], 0); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0425]: cannot find value `Utils` in this scope --> QuadraticRootsCmdLine.rs:16:14 | 16 | let B:f64 = Utils.stodWithDefault(args[2], 0); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> QuadraticRootsCmdLine.rs:16:36 | 16 | let B:f64 = Utils.stodWithDefault(args[2], 0); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0425]: cannot find value `Utils` in this scope --> QuadraticRootsCmdLine.rs:17:14 | 17 | let C:f64 = Utils.stodWithDefault(args[3], 0); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> QuadraticRootsCmdLine.rs:17:36 | 17 | let C:f64 = Utils.stodWithDefault(args[3], 0); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> QuadraticRootsCmdLine.rs:18:39 | 18 | 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 | 18 | let mut discriminant:f64 = B * B - 4.0f64 * A * C; | + error[E0425]: cannot find function `sqrt` in this scope --> QuadraticRootsCmdLine.rs:19:17 | 19 | discriminant = sqrt(discriminant); | ^^^^ not found in this scope error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> QuadraticRootsCmdLine.rs:20:47 | 20 | 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 | 20 | let mut root1:f64 = (-B + discriminant) / (2.0f64 * A); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> QuadraticRootsCmdLine.rs:21:47 | 21 | 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 | 21 | let mut root2:f64 = (-B - discriminant) / (2.0f64 * A); | + error: aborting due to 13 previous errors Some errors have detailed explanations: E0425, E0610. For more information about an error, try `rustc --explain E0425`. $ rustc QuadraticRootsCmdLine.rs error: unknown format trait `s` --> QuadraticRootsCmdLine.rs:12:38 | 12 | println!("{}", format!("Syntax: {0:s} a b c", utils::program_name().expect("program name should not be empty!"))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error[E0425]: cannot find value `args` in this scope --> QuadraticRootsCmdLine.rs:11:5 | 11 | if args.len() != 4 { | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> QuadraticRootsCmdLine.rs:13:3 | 13 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::process::exit; | error[E0425]: cannot find value `Utils` in this scope --> QuadraticRootsCmdLine.rs:15:14 | 15 | let A:f64 = Utils.stodWithDefault(args[1], 0); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> QuadraticRootsCmdLine.rs:15:36 | 15 | let A:f64 = Utils.stodWithDefault(args[1], 0); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0425]: cannot find value `Utils` in this scope --> QuadraticRootsCmdLine.rs:16:14 | 16 | let B:f64 = Utils.stodWithDefault(args[2], 0); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> QuadraticRootsCmdLine.rs:16:36 | 16 | let B:f64 = Utils.stodWithDefault(args[2], 0); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0425]: cannot find value `Utils` in this scope --> QuadraticRootsCmdLine.rs:17:14 | 17 | let C:f64 = Utils.stodWithDefault(args[3], 0); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> QuadraticRootsCmdLine.rs:17:36 | 17 | let C:f64 = Utils.stodWithDefault(args[3], 0); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> QuadraticRootsCmdLine.rs:18:39 | 18 | 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 | 18 | let mut discriminant:f64 = B * B - 4.0f64 * A * C; | + error[E0425]: cannot find function `sqrt` in this scope --> QuadraticRootsCmdLine.rs:19:17 | 19 | discriminant = sqrt(discriminant); | ^^^^ not found in this scope error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> QuadraticRootsCmdLine.rs:20:47 | 20 | 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 | 20 | let mut root1:f64 = (-B + discriminant) / (2.0f64 * A); | + error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> QuadraticRootsCmdLine.rs:21:47 | 21 | 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 | 21 | let mut root2:f64 = (-B - discriminant) / (2.0f64 * A); | + error: aborting due to 13 previous errors Some errors have detailed explanations: E0425, E0610. For more information about an error, try `rustc --explain E0425`.

Solution