use
std::io;
use
std::process::
exit
;
fn
main() {
println!(
"enter a number:"
);
let
mut
stra = String::new();
io::stdin()
.read_line(&
mut
stra)
.expect(
"failed to read input."
);
println!(
"enter b number:"
);
let
mut
strb = String::new();
io::stdin()
.read_line(&
mut
strb)
.expect(
"failed to read input."
);
let
a: i32 = stra.trim().parse().expect(
"invalid input"
);
let
b: i32 = strb.trim().parse().expect(
"invalid input"
);
println!("choose your calculation: \n1.sum
\n2.difference
\n3.product
\n4.quotient
\n5.remainder\n");
let
mut
choose = String::new();
io::stdin()
.read_line(&
mut
choose)
.expect(
"failed to read input."
);
let
c: i32 = choose.trim().parse().expect(
"invalid input"
);
if
c==1{sum(a,b);}
else
if
c==2{sub(a,b);}
else
if
c==3{mul(a,b);}
else
if
c==4{quo(a,b);}
else
if
c==5{rem(a,b);}
else
{println!(
"Invalid argument"
);
exit
(1);}
}
fn
sum(x: i32, y: i32) {
println!(
"sum = {}"
, x+y);
}
fn
sub(x: i32, y: i32) {
println!(
"difference = {}"
, x-y);
}
fn
mul(x: i32, y: i32) {
println!(
"product = {}"
, x*y);
}
fn
quo(x: i32, y: i32) {
println!(
"quotient = {}"
, x/y);
}
fn
rem(x: i32, y: i32) {
println!(
"remainder = {}"
, x%y);
}