Project: Aligning Floating Point with printf()
Write a program that demonstrates floating point formatting using default (most compact), fixed point and exponential formats using printf() and/or sprintf() style output. Print using no precision, precision of 2 and a field width of 10 with precision 2. Your program should reproduce the output shown using the following variables:
- π = 3.141592653589793
- 𝑒 = 2.718281828459045
- avogadro = 6.0221412927e23
- electron_mass = 9.1093821545e-31
Output
$ rustc AligningFloatingPointWithPrintf.rs
error[E0425]: cannot find value `PI` in this scope
--> AligningFloatingPointWithPrintf.rs:14:47
|
14 | println!("{}", sprintf("π: %g %.2g |%10.2g|",PI,PI,PI));
| ^^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::PI;
|
7 + use std::f32::consts::PI;
|
error[E0425]: cannot find value `PI` in this scope
--> AligningFloatingPointWithPrintf.rs:14:50
|
14 | println!("{}", sprintf("π: %g %.2g |%10.2g|",PI,PI,PI));
| ^^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::PI;
|
7 + use std::f32::consts::PI;
|
error[E0425]: cannot find value `PI` in this scope
--> AligningFloatingPointWithPrintf.rs:14:53
|
14 | println!("{}", sprintf("π: %g %.2g |%10.2g|",PI,PI,PI));
| ^^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::PI;
|
7 + use std::f32::consts::PI;
|
error[E0425]: cannot find value `E` in this scope
--> AligningFloatingPointWithPrintf.rs:15:47
|
15 | println!("{}", sprintf("ℯ: %g %.2g |%10.2g|",E,E,E));
| ^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::E;
|
7 + use std::f32::consts::E;
|
error[E0425]: cannot find value `E` in this scope
--> AligningFloatingPointWithPrintf.rs:15:49
|
15 | println!("{}", sprintf("ℯ: %g %.2g |%10.2g|",E,E,E));
| ^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::E;
|
7 + use std::f32::consts::E;
|
error[E0425]: cannot find value `E` in this scope
--> AligningFloatingPointWithPrintf.rs:15:51
|
15 | println!("{}", sprintf("ℯ: %g %.2g |%10.2g|",E,E,E));
| ^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::E;
|
7 + use std::f32::consts::E;
|
error[E0425]: cannot find value `PI` in this scope
--> AligningFloatingPointWithPrintf.rs:20:47
|
20 | println!("{}", sprintf("π: %f %.2f |%10.2f|",PI,PI,PI));
| ^^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::PI;
|
7 + use std::f32::consts::PI;
|
error[E0425]: cannot find value `PI` in this scope
--> AligningFloatingPointWithPrintf.rs:20:50
|
20 | println!("{}", sprintf("π: %f %.2f |%10.2f|",PI,PI,PI));
| ^^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::PI;
|
7 + use std::f32::consts::PI;
|
error[E0425]: cannot find value `PI` in this scope
--> AligningFloatingPointWithPrintf.rs:20:53
|
20 | println!("{}", sprintf("π: %f %.2f |%10.2f|",PI,PI,PI));
| ^^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::PI;
|
7 + use std::f32::consts::PI;
|
error[E0425]: cannot find value `E` in this scope
--> AligningFloatingPointWithPrintf.rs:21:47
|
21 | println!("{}", sprintf("ℯ: %f %.2f |%10.2f|",E,E,E));
| ^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::E;
|
7 + use std::f32::consts::E;
|
error[E0425]: cannot find value `E` in this scope
--> AligningFloatingPointWithPrintf.rs:21:49
|
21 | println!("{}", sprintf("ℯ: %f %.2f |%10.2f|",E,E,E));
| ^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::E;
|
7 + use std::f32::consts::E;
|
error[E0425]: cannot find value `E` in this scope
--> AligningFloatingPointWithPrintf.rs:21:51
|
21 | println!("{}", sprintf("ℯ: %f %.2f |%10.2f|",E,E,E));
| ^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::E;
|
7 + use std::f32::consts::E;
|
error[E0425]: cannot find value `PI` in this scope
--> AligningFloatingPointWithPrintf.rs:26:47
|
26 | println!("{}", sprintf("π: %e %.2e |%10.2e|",PI,PI,PI));
| ^^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::PI;
|
7 + use std::f32::consts::PI;
|
error[E0425]: cannot find value `PI` in this scope
--> AligningFloatingPointWithPrintf.rs:26:50
|
26 | println!("{}", sprintf("π: %e %.2e |%10.2e|",PI,PI,PI));
| ^^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::PI;
|
7 + use std::f32::consts::PI;
|
error[E0425]: cannot find value `PI` in this scope
--> AligningFloatingPointWithPrintf.rs:26:53
|
26 | println!("{}", sprintf("π: %e %.2e |%10.2e|",PI,PI,PI));
| ^^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::PI;
|
7 + use std::f32::consts::PI;
|
error[E0425]: cannot find value `E` in this scope
--> AligningFloatingPointWithPrintf.rs:27:47
|
27 | println!("{}", sprintf("ℯ: %e %.2e |%10.2e|",E,E,E));
| ^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::E;
|
7 + use std::f32::consts::E;
|
error[E0425]: cannot find value `E` in this scope
--> AligningFloatingPointWithPrintf.rs:27:49
|
27 | println!("{}", sprintf("ℯ: %e %.2e |%10.2e|",E,E,E));
| ^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::E;
|
7 + use std::f32::consts::E;
|
error[E0425]: cannot find value `E` in this scope
--> AligningFloatingPointWithPrintf.rs:27:51
|
27 | println!("{}", sprintf("ℯ: %e %.2e |%10.2e|",E,E,E));
| ^ not found in this scope
|
help: consider importing one of these items
|
7 + use consts::E;
|
7 + use std::f32::consts::E;
|
warning: unused import: `std::f64::consts`
--> AligningFloatingPointWithPrintf.rs:7:5
|
7 | use std::f64::consts;
| ^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0425]: cannot find function `sprintf` in this scope
--> AligningFloatingPointWithPrintf.rs:14:17
|
14 | println!("{}", sprintf("π: %g %.2g |%10.2g|",PI,PI,PI));
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `sprintf` in this scope
--> AligningFloatingPointWithPrintf.rs:15:17
|
15 | println!("{}", sprintf("ℯ: %g %.2g |%10.2g|",E,E,E));
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `sprintf` in this scope
--> AligningFloatingPointWithPrintf.rs:16:17
|
16 | println!("{}", sprintf("N\u{2090}: %g %.2g |%10.2g|",avogadro,avogadro,avogadro));
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `sprintf` in this scope
--> AligningFloatingPointWithPrintf.rs:17:17
|
17 | println!("{}", sprintf("m\u{2091}: %g %.2g |%10.2g|",electron_mass,electron_mass,electron_mass));
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `sprintf` in this scope
--> AligningFloatingPointWithPrintf.rs:20:17
|
20 | println!("{}", sprintf("π: %f %.2f |%10.2f|",PI,PI,PI));
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `sprintf` in this scope
--> AligningFloatingPointWithPrintf.rs:21:17
|
21 | println!("{}", sprintf("ℯ: %f %.2f |%10.2f|",E,E,E));
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `sprintf` in this scope
--> AligningFloatingPointWithPrintf.rs:22:17
|
22 | println!("{}", sprintf("N\u{2090}: %f %.2f |%10.2f|",avogadro,avogadro,avogadro));
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `sprintf` in this scope
--> AligningFloatingPointWithPrintf.rs:23:17
|
23 | println!("{}", sprintf("m\u{2091}: %f %.2f |%10.2f|",electron_mass,electron_mass,electron_mass));
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `sprintf` in this scope
--> AligningFloatingPointWithPrintf.rs:26:17
|
26 | println!("{}", sprintf("π: %e %.2e |%10.2e|",PI,PI,PI));
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `sprintf` in this scope
--> AligningFloatingPointWithPrintf.rs:27:17
|
27 | println!("{}", sprintf("ℯ: %e %.2e |%10.2e|",E,E,E));
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `sprintf` in this scope
--> AligningFloatingPointWithPrintf.rs:28:17
|
28 | println!("{}", sprintf("N\u{2090}: %e %.2e |%10.2e|",avogadro,avogadro,avogadro));
| ^^^^^^^ not found in this scope
error[E0425]: cannot find function `sprintf` in this scope
--> AligningFloatingPointWithPrintf.rs:29:17
|
29 | println!("{}", sprintf("m\u{2091}: %e %.2e |%10.2e|",electron_mass,electron_mass,electron_mass));
| ^^^^^^^ not found in this scope
error: aborting due to 30 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0425`.