Basic Operations
Part of the Fundamentals section of Coddy's Rust journey — lesson 35 of 75.
Challenge
BeginnerAdd the basic arithmetic operations (addition, subtraction, multiplication, and division) on num1 and num2. Store the results in variables named sum, difference, product, and quotient, respectively. Print the results to the console using println! in the following format:
Sum: [sum]
Difference: [difference]
Product: [product]
Quotient: [quotient]Try it yourself
use std::io;
fn main() {
println!("Calculator App");
let mut input_num1 = String::new();
let mut input_num2 = String::new();
io::stdin().read_line(&mut input_num1).unwrap();
io::stdin().read_line(&mut input_num2).unwrap();
let num1: f64 = input_num1.trim().parse().unwrap();
let num2: f64 = input_num2.trim().parse().unwrap();
println!("{}", num1);
println!("{}", num2);
}All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsComparison OperatorsString Comparison5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 33Variables Part 2
Type DeclarationNaming ConventionsType InferenceRecap - Initialize VariablesType Casting9Loops
For Over SeriesWhile LoopBreakContinueNested LoopLoop LabelsInfinite LoopRecap - Dynamic Input