Pure Programmer
Blue Matrix


Cluster Map

Project: Average Filter

Write a filter program that accepts text representations of floating point values on the standard input, one per line. The program should then compute the average of the input values. Finally the program should output the value of the average to 16 decimal places on a single line so that it can easily be used by other programs.

Output
$ rustc AverageFilter.rs error: unknown format trait `g` --> AverageFilter.rs:37:33 | 37 | println!("{}", format!("{0:.16g}", total / (count) as f64)); | ^ | = 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 --> AverageFilter.rs:18:12 | 18 | line = &(Utils.trim(line)); | ^^^^^ not found in this scope error[E0308]: mismatched types --> AverageFilter.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 --> AverageFilter.rs:17:8 | 17 | while getline(line) { | ^^^^^^^ not found in this scope error[E0425]: cannot find function `stod` in this scope --> AverageFilter.rs:20:8 | 20 | d = stod(line)?; | ^^^^ not found in this scope error[E0425]: cannot find function `strlen` in this scope --> AverageFilter.rs:28:9 | 28 | 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 AverageFilter.rs error: unknown format trait `g` --> AverageFilter.rs:37:33 | 37 | println!("{}", format!("{0:.16g}", total / (count) as f64)); | ^ | = 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 --> AverageFilter.rs:18:12 | 18 | line = &(Utils.trim(line)); | ^^^^^ not found in this scope error[E0308]: mismatched types --> AverageFilter.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 --> AverageFilter.rs:17:8 | 17 | while getline(line) { | ^^^^^^^ not found in this scope error[E0425]: cannot find function `stod` in this scope --> AverageFilter.rs:20:8 | 20 | d = stod(line)?; | ^^^^ not found in this scope error[E0425]: cannot find function `strlen` in this scope --> AverageFilter.rs:28:9 | 28 | 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 AverageFilter.rs error: unknown format trait `g` --> AverageFilter.rs:37:33 | 37 | println!("{}", format!("{0:.16g}", total / (count) as f64)); | ^ | = 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 --> AverageFilter.rs:18:12 | 18 | line = &(Utils.trim(line)); | ^^^^^ not found in this scope error[E0308]: mismatched types --> AverageFilter.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 --> AverageFilter.rs:17:8 | 17 | while getline(line) { | ^^^^^^^ not found in this scope error[E0425]: cannot find function `stod` in this scope --> AverageFilter.rs:20:8 | 20 | d = stod(line)?; | ^^^^ not found in this scope error[E0425]: cannot find function `strlen` in this scope --> AverageFilter.rs:28:9 | 28 | 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