Pure Programmer
Blue Matrix


Cluster Map

Project: Absolute Value

Write a program to compute [[Absolute_value|absolute values]]. The absolute value of a number |x| is x if x is positive and -x if x is negative.

Output
$ rustc AbsoluteValue.rs error: unknown format trait `d` --> AbsoluteValue.rs:9:30 | 9 | println!("{}", format!("|{0:d}| = {1:d}", x, (if x < 0 { -x } else { x }))); | ^ | = 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: unknown format trait `d` --> AbsoluteValue.rs:9:39 | 9 | println!("{}", format!("|{0:d}| = {1:d}", x, (if x < 0 { -x } else { x }))); | ^ | = 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: unknown format trait `d` --> AbsoluteValue.rs:11:30 | 11 | println!("{}", format!("|{0:d}| = {1:d}", x, (if x < 0 { -x } else { x }))); | ^ | = 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: unknown format trait `d` --> AbsoluteValue.rs:11:39 | 11 | println!("{}", format!("|{0:d}| = {1:d}", x, (if x < 0 { -x } else { x }))); | ^ | = 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: unknown format trait `d` --> AbsoluteValue.rs:13:30 | 13 | println!("{}", format!("|{0:d}| = {1:d}", x, (if x < 0 { -x } else { x }))); | ^ | = 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: unknown format trait `d` --> AbsoluteValue.rs:13:39 | 13 | println!("{}", format!("|{0:d}| = {1:d}", x, (if x < 0 { -x } else { x }))); | ^ | = 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: unknown format trait `f` --> AbsoluteValue.rs:16:30 | 16 | println!("{}", format!("|{0:f}| = {1:f}", y, (if y < 0 { -y } else { y }))); | ^ | = 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: unknown format trait `f` --> AbsoluteValue.rs:16:39 | 16 | println!("{}", format!("|{0:f}| = {1:f}", y, (if y < 0 { -y } else { y }))); | ^ | = 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: unknown format trait `f` --> AbsoluteValue.rs:18:30 | 18 | println!("{}", format!("|{0:f}| = {1:f}", y, (if y < 0 { -y } else { y }))); | ^ | = 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: unknown format trait `f` --> AbsoluteValue.rs:18:39 | 18 | println!("{}", format!("|{0:f}| = {1:f}", y, (if y < 0 { -y } else { y }))); | ^ | = 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: unknown format trait `f` --> AbsoluteValue.rs:20:30 | 20 | println!("{}", format!("|{0:f}| = {1:f}", y, (if y < 0 { -y } else { y }))); | ^ | = 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: unknown format trait `f` --> AbsoluteValue.rs:20:39 | 20 | println!("{}", format!("|{0:f}| = {1:f}", y, (if y < 0 { -y } else { y }))); | ^ | = 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[E0308]: mismatched types --> AbsoluteValue.rs:16:55 | 16 | println!("{}", format!("|{0:f}| = {1:f}", y, (if y < 0 { -y } else { y }))); | - ^ | | | | | expected `f64`, found integer | | help: use a float literal: `0.0` | expected because this is `f64` error[E0308]: mismatched types --> AbsoluteValue.rs:18:55 | 18 | println!("{}", format!("|{0:f}| = {1:f}", y, (if y < 0 { -y } else { y }))); | - ^ | | | | | expected `f64`, found integer | | help: use a float literal: `0.0` | expected because this is `f64` error[E0308]: mismatched types --> AbsoluteValue.rs:20:55 | 20 | println!("{}", format!("|{0:f}| = {1:f}", y, (if y < 0 { -y } else { y }))); | - ^ | | | | | expected `f64`, found integer | | help: use a float literal: `0.0` | expected because this is `f64` error: aborting due to 15 previous errors For more information about this error, try `rustc --explain E0308`.

Solution