Pure Programmer
Blue Matrix


Cluster Map

Project: Supermarket Sale (Revisited)

A supermarket is having a sale on 2-liter bottles of soda: buy 2, get one free. A 2-liter bottle of soda is priced at $1.29. Write a program that prints the price for 1 through 12 bottles of soda. Remember to round prices to dollars and cents.

Output
$ rustc SupermarketSale2.rs error: unknown format trait `d` --> SupermarketSale2.rs:15:31 | 15 | println!("{}", format!("{0:d} bottle(s) is ${1:.2f}", i, price)); | ^ | = 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` --> SupermarketSale2.rs:15:53 | 15 | println!("{}", format!("{0:d} bottle(s) is ${1:.2f}", i, price)); | ^ | = 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[E0277]: the trait bound `f64: From<isize>` is not satisfied --> SupermarketSale2.rs:14:29 | 14 | price -= floor(f64::from(i) / f64::from(freeBottle)) * pricePerBottle; | --------- ^ the trait `From<isize>` is not implemented for `f64` | | | required by a bound introduced by this call | = help: the following other types implement trait `From<T>`: <f64 as From<bool>> <f64 as From<f32>> <f64 as From<i16>> <f64 as From<i32>> <f64 as From<i8>> <f64 as From<u16>> <f64 as From<u32>> <f64 as From<u8>> error[E0277]: the trait bound `f64: From<isize>` is not satisfied --> SupermarketSale2.rs:14:44 | 14 | price -= floor(f64::from(i) / f64::from(freeBottle)) * pricePerBottle; | --------- ^^^^^^^^^^ the trait `From<isize>` is not implemented for `f64` | | | required by a bound introduced by this call | = help: the following other types implement trait `From<T>`: <f64 as From<bool>> <f64 as From<f32>> <f64 as From<i16>> <f64 as From<i32>> <f64 as From<i8>> <f64 as From<u16>> <f64 as From<u32>> <f64 as From<u8>> error[E0425]: cannot find function `floor` in this scope --> SupermarketSale2.rs:14:13 | 14 | price -= floor(f64::from(i) / f64::from(freeBottle)) * pricePerBottle; | ^^^^^ not found in this scope | help: use the `.` operator to call the method `floor` on `f64` | 14 | price -= (f64::from(i) / f64::from(freeBottle)).floor() * pricePerBottle; | ~ ~~~~~~~~~ error: aborting due to 5 previous errors Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`.

Solution