Console 2: Mr Bargain Tout
This commit is contained in:
6
Session1/TP1/MrBargainTout/Cargo.toml
Normal file
6
Session1/TP1/MrBargainTout/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "mrbargaintout"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
57
Session1/TP1/MrBargainTout/src/main.rs
Normal file
57
Session1/TP1/MrBargainTout/src/main.rs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut object_name: String = String::new();
|
||||||
|
let mut posted_price: f32 = 0.0;
|
||||||
|
let mut paid_price: f32 = 0.0;
|
||||||
|
|
||||||
|
print!("Enter the object's name: ");
|
||||||
|
let _ = io::stdout().flush();
|
||||||
|
io::stdin()
|
||||||
|
.read_line(&mut object_name)
|
||||||
|
.expect("failed to read from stdin");
|
||||||
|
object_name = object_name.trim().to_string();
|
||||||
|
|
||||||
|
let mut postedprice_isint: bool = false;
|
||||||
|
while !postedprice_isint {
|
||||||
|
print!("Enter the posted price: ");
|
||||||
|
_ = io::stdout().flush();
|
||||||
|
let mut input_text = String::new();
|
||||||
|
io::stdin()
|
||||||
|
.read_line(&mut input_text)
|
||||||
|
.expect("failed to read from stdin");
|
||||||
|
|
||||||
|
match input_text.trim().parse::<f32>() {
|
||||||
|
Ok(i) => {
|
||||||
|
posted_price = i;
|
||||||
|
postedprice_isint = true;
|
||||||
|
}
|
||||||
|
Err(..) => println!("Input must be an integer!"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut paidprice_isint: bool = false;
|
||||||
|
while !paidprice_isint {
|
||||||
|
print!("Enter the paid price: ");
|
||||||
|
_ = io::stdout().flush();
|
||||||
|
let mut input_text = String::new();
|
||||||
|
io::stdin()
|
||||||
|
.read_line(&mut input_text)
|
||||||
|
.expect("failed to read from stdin");
|
||||||
|
|
||||||
|
match input_text.trim().parse::<f32>() {
|
||||||
|
Ok(i) => {
|
||||||
|
paid_price = i;
|
||||||
|
paidprice_isint = true;
|
||||||
|
}
|
||||||
|
Err(..) => println!("Input must be an integer!"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("The object's name is: {}", object_name);
|
||||||
|
println!("The posted price is: {:.2} $", posted_price);
|
||||||
|
println!("The paid price is: {:.2} $", paid_price);
|
||||||
|
let diff: f32 = posted_price - paid_price;
|
||||||
|
println!("Difference between the prices: {:.2} $", diff);
|
||||||
|
println!("Rebate percentage: {:.2} %", diff / posted_price * 100.0);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user