Pure Programmer
Blue Matrix


Cluster Map

Project: Total Filter (Floating Point)

Write a filter program that accepts text representations of floating point values, one per line, and then computes and prints the total. The program should print an error to STDERR if a line of input can't be parsed as a floating point value.

Output
$ rustc TotalFilterFP.rs error: unknown format trait `g` --> TotalFilterFP.rs:34:29 | 34 | println!("{}", format!("{0:g}", total)); | ^ | = 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 `Utils` in this scope --> TotalFilterFP.rs:17:12 | 17 | line = &(Utils.trim(line)); | ^^^^^ not found in this scope error[E0308]: mismatched types --> TotalFilterFP.rs:14:22 | 14 | let mut total:f64 = 0; | --- ^ | | | | | expected `f64`, found integer | | help: use a float literal: `0.0` | expected due to this error[E0425]: cannot find function `getline` in this scope --> TotalFilterFP.rs:16:8 | 16 | while getline(line) { | ^^^^^^^ not found in this scope error[E0425]: cannot find function `stod` in this scope --> TotalFilterFP.rs:19:8 | 19 | d = stod(line)?; | ^^^^ not found in this scope error[E0425]: cannot find function `strlen` in this scope --> TotalFilterFP.rs:26:9 | 26 | if strlen(line) > 0 { | ^^^^^^ not found in this scope error: aborting due to 6 previous errors Some errors have detailed explanations: E0308, E0425. For more information about an error, try `rustc --explain E0308`. $ rustc TotalFilterFP.rs error: unknown format trait `g` --> TotalFilterFP.rs:34:29 | 34 | println!("{}", format!("{0:g}", total)); | ^ | = 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 `Utils` in this scope --> TotalFilterFP.rs:17:12 | 17 | line = &(Utils.trim(line)); | ^^^^^ not found in this scope error[E0308]: mismatched types --> TotalFilterFP.rs:14:22 | 14 | let mut total:f64 = 0; | --- ^ | | | | | expected `f64`, found integer | | help: use a float literal: `0.0` | expected due to this error[E0425]: cannot find function `getline` in this scope --> TotalFilterFP.rs:16:8 | 16 | while getline(line) { | ^^^^^^^ not found in this scope error[E0425]: cannot find function `stod` in this scope --> TotalFilterFP.rs:19:8 | 19 | d = stod(line)?; | ^^^^ not found in this scope error[E0425]: cannot find function `strlen` in this scope --> TotalFilterFP.rs:26:9 | 26 | if strlen(line) > 0 { | ^^^^^^ not found in this scope error: aborting due to 6 previous errors Some errors have detailed explanations: E0308, E0425. For more information about an error, try `rustc --explain E0308`. $ rustc TotalFilterFP.rs error: unknown format trait `g` --> TotalFilterFP.rs:34:29 | 34 | println!("{}", format!("{0:g}", total)); | ^ | = 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 `Utils` in this scope --> TotalFilterFP.rs:17:12 | 17 | line = &(Utils.trim(line)); | ^^^^^ not found in this scope error[E0308]: mismatched types --> TotalFilterFP.rs:14:22 | 14 | let mut total:f64 = 0; | --- ^ | | | | | expected `f64`, found integer | | help: use a float literal: `0.0` | expected due to this error[E0425]: cannot find function `getline` in this scope --> TotalFilterFP.rs:16:8 | 16 | while getline(line) { | ^^^^^^^ not found in this scope error[E0425]: cannot find function `stod` in this scope --> TotalFilterFP.rs:19:8 | 19 | d = stod(line)?; | ^^^^ not found in this scope error[E0425]: cannot find function `strlen` in this scope --> TotalFilterFP.rs:26:9 | 26 | if strlen(line) > 0 { | ^^^^^^ not found in this scope error: aborting due to 6 previous errors Some errors have detailed explanations: E0308, E0425. For more information about an error, try `rustc --explain E0308`.

Solution