Pure Programmer
Blue Matrix


Cluster Map

Project: Sample Mean

To calculate the [[Sample_mean_and_covariance|mean]] (or average)

is the sum of a number of random samples divided by the number in the sample. Write a program that computes the mean of 10 random floating point values in the interval [0,1). This closed/open [[Interval_(mathematics)|interval]] notation means 0 is in the range but 1 is not. Print the mean to four decimal places. Run the program multiple times to confirm that you get different results each time.

Output
$ rustc SampleMean.rs error: unknown format trait `f` --> SampleMean.rs:19:44 | 19 | println!("{}", format!("Sample mean: {0:.4f}", sum / f64::from(10))); | ^ | = 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 function `random` in this scope --> SampleMean.rs:9:9 | 9 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:10:9 | 10 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:11:9 | 11 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:12:9 | 12 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:13:9 | 13 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:14:9 | 14 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:15:9 | 15 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:16:9 | 16 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:17:9 | 17 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:18:9 | 18 | sum += random(); | ^^^^^^ not found in this scope error: aborting due to 11 previous errors For more information about this error, try `rustc --explain E0425`. $ rustc SampleMean.rs error: unknown format trait `f` --> SampleMean.rs:19:44 | 19 | println!("{}", format!("Sample mean: {0:.4f}", sum / f64::from(10))); | ^ | = 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 function `random` in this scope --> SampleMean.rs:9:9 | 9 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:10:9 | 10 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:11:9 | 11 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:12:9 | 12 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:13:9 | 13 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:14:9 | 14 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:15:9 | 15 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:16:9 | 16 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:17:9 | 17 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:18:9 | 18 | sum += random(); | ^^^^^^ not found in this scope error: aborting due to 11 previous errors For more information about this error, try `rustc --explain E0425`. $ rustc SampleMean.rs error: unknown format trait `f` --> SampleMean.rs:19:44 | 19 | println!("{}", format!("Sample mean: {0:.4f}", sum / f64::from(10))); | ^ | = 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 function `random` in this scope --> SampleMean.rs:9:9 | 9 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:10:9 | 10 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:11:9 | 11 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:12:9 | 12 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:13:9 | 13 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:14:9 | 14 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:15:9 | 15 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:16:9 | 16 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:17:9 | 17 | sum += random(); | ^^^^^^ not found in this scope error[E0425]: cannot find function `random` in this scope --> SampleMean.rs:18:9 | 18 | sum += random(); | ^^^^^^ not found in this scope error: aborting due to 11 previous errors For more information about this error, try `rustc --explain E0425`.

Solution