Two brands sell the same product. Show the one with the higher rating.
You start with: an empty editor (no starter code). Declare this data yourself:
let brand1 = "TechPro";
let rating1 = 4;
let brand2 = "MegaCorp";
let rating2 = 5;
Build:
1. MegaCorp (5)
Rules:
- Use
if/elseto pick the winner:brand1whenrating1 > rating2, otherwisebrand2. - Declare
best_brandandbest_ratingwithout a value (let best_brand;) and assign them in the branches. - Format the result as
"1. Brand (rating)"and print it withprintln!(...).
Pick the winner into
best_brand and best_rating first, then build the output text from them.
format!("1. {} ({})", brand, rating) builds text from several values, numbers included.
let brand1 = "TechPro";
let rating1 = 4;
let brand2 = "MegaCorp";
let rating2 = 5;
let best_brand;
let best_rating;
if rating1 > rating2 {
best_brand = brand1;
best_rating = rating1;
} else {
best_brand = brand2;
best_rating = rating2;
}
println!("1. {} ({})", best_brand, best_rating);
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
