Quiz: Rarity Names
This program should print Magic Ring: rare, but it prints Magic Ring: legendary. Click the line with the mistake.
1#include <iostream>
2#include <string>
3
4enum class Rarity { Common, Rare, Legendary };
5
6struct Item {
7 std::string name;
8 Rarity rarity;
9};
10
11std::string rarityName(Rarity rarity) {
12 if (rarity == Rarity::Common) {
13 return "common";
14 } else if (rarity == Rarity::Common) {
15 return "rare";
16 }
17 return "legendary";
18}
19
20int main() {
21 Item ring = {"Magic Ring", Rarity::Rare};
22 std::cout << ring.name << ": " << rarityName(ring.rarity) << std::endl;
23 return 0;
24}