Practice
Practice - 022
A program to calculate electricity bill by reading units consumed
use text_io::scan;
/** * Units >= 250 - Flat charge 1000$ * 150 <= Units < 250 - Charge = 200 + units*1.50 * 100 <= Units < 150 - Charge = 100 + units*1.00 * 50 <= Units < 100 - Charge = 50 + units*0.50 * Units < 50 - Flat charge 10$ */
fn main() { practice22()}
fn practice22() { let units_consumed: i32; let bill: f32;
println!("Enter the number of units consumed:"); scan!("{}", units_consumed);
if units_consumed >= 250 { bill = 1000.0; } else if units_consumed < 250 && units_consumed >= 150 { bill = 200.0 + units_consumed as f32 * 1.50; } else if units_consumed < 150 && units_consumed >= 100 { bill = 100.0 + units_consumed as f32 * 1.00; } else if units_consumed < 100 && units_consumed >= 50 { bill = 50.0 + units_consumed as f32 * 0.50; } else { bill = 10.0; }
println!("Amount to be paid = {}", bill);}
Config
[package]name = "practice"version = "0.1.0"edition = "2021"
[dependencies]text_io = "0.1.12"
Result
Enter the number of units consumed:55Amount to be paid = 77.5