It's time to slay some monsters. You choose a master—Turael, Duradel, or Konar—and that choice governs which monsters are on the table, what the assignment odds look like, and how many you might be sent to defeat. Your program will read the player’s combat and slayer levels, validate that they’re eligible for the chosen master, apply the correct rules (including Duradel’s “halving” twist), and present a clean, aligned table of probabilities and max assignments. Along the way you’ll practice the everyday tools of real programs: careful input handling, selection, and polished console formatting with <iomanip>
.
Why this matters: these mechanics map directly to professional work. Eligibility checks, policy- and tier-based behavior, and human-readable reports appear in everything from checkout flows to access control, pricing tiers, and operations dashboards. By turning a game rulebook into code you’ll learn how to translate requirements into precise logic, fail fast with clear messages, and present results stakeholders can trust. Master these habits now and you’ll be faster and safer later—both in this course and on the job.
In Old School Runescape, to gain money and advance combat levels players can get tasks to kill monsters from slayer masters. Players start getting tasks from slayer master Turael, but move on to unlocking slayer masters Duradel and Konar as they advance their combat and slayer levels. Write a program to read a player's combat and slayer levels and what slayer master they want to do, then output a table of the tasks the player may get assigned based on their combat and slayer level. You will need to:
Read the player's combat level as an integer. Use the prompt: "Combat Level: "
Validate combat level:
Error: Invalid number
and terminate the program.Error: Minimum combat level is 3
and terminate the program.Error: Maximum combat level is 126
and terminate the program.Read the player's slayer level as an integer. Use the prompt: "Slayer Level: "
Validate slayer level:
Error: Invalid number
and terminate the program.Error: Minimum slayer level is 1
and terminate the program.Error: Maximum slayer level is 99
and terminate the program.Read the player's slayer master choice as a character. Use the prompt:
(T/t)urael (D/d)uradel (K/k)onar Selection:
Select the slayer master with a switch
statement (and validate the choice). Use a switch
on the slayer master selection the player previously made to route logic to Turael, Duradel, or Konar. If the selection is not recognized, print Error: Invalid slayer master selection
and terminate the program
Important: You must use a switch for master selection. Not using a switch here will result in a point deduction of 50%.
Inside the switch: Validate master-specific requirements:
Error: Must have combat level 100 and slayer level 50 to visit Duradel
and terminate the program.Error: Must have combat level 75 to visit Konar
and terminate the program. Inside the switch: Set monster task probabilities and max assigned counts. Assign the values below for the selected master. For Duradel, if slayer < 75, print Kill counts halved because of slayer level
and halve all max counts (integer division).
Important: Assigning probabilities and counts must be performed inside the relevant switch case.
Slayer Master | Kalphite (prob / max) | Ankou (prob / max) | Dragon (prob / max) | Boss (prob / max) | Notes |
---|---|---|---|---|---|
Turael | 74%/15 | 24% / 25 | 0% / 0 | 2% / 1 | - |
Duradel | 30% / 120 | 50% / 250 | 0% / 0 | 20% / 5 | If slayer < 75: print halving notice and halve all max counts |
Konar | 25% / 30 | 35% / 100 | 20% / 100 | 20% / 2 | - |
Output the results table. Print a neatly aligned table with monster (left justified in a width of 10), probability (right justified in a width of 12), and max assigned (right justified in a width of 15) using <iomanip>
.
An example of an interaction with your program is shown below. When interacted with, your program must produce the exact same results.
AS3 % ./a.out Combat Level: error Error: Invalid number
Too small/large combat levels should display similarly with respective errors.
AS3 % ./a.out Combat Level: 10 Slayer Level: 100 Error: Maximum slayer level is 99
Input failure/too small slayer levels should display similarly with respective errors.
AS3 % ./a.out Combat Level: 99 Slayer Level: 99 (T/t)urael (D/d)uradel (K/k)onar Selection: e Invalid slayer master selection
AS3 % ./a.out Combat Level: 99 Slayer Level: 99 (T/t)urael (D/d)uradel (K/k)onar Selection: t Monster Probability Max Assigned ------------------------------------- Kalphite 74% 15 Ankou 24% 25 Dragon 0% 0 Boss 2% 1
AS3 % ./a.out Combat Level: 10 Slayer Level: 50 (T/t)urael (D/d)uradel (K/k)onar Selection: d Must have combat level 100 and slayer level 50 to visit Duradel
AS3 % ./a.out Combat Level: 100 Slayer Level: 50 (T/t)urael (D/d)uradel (K/k)onar Selection: D Kill counts halved because of slayer level Monster Probability Max Assigned ------------------------------------- Kalphite 30% 60 Ankou 50% 125 Dragon 0% 0 Boss 20% 2
See CodeGrade for more examples.
Note: The line breaks after the inputs in the example output formatting above are the ones placed into the terminal by the user hitting enter
on their keyboard to input. CodeGrade does not enter values with a keyboard, but rather supplies input via Linux redirection to programs. So in CodeGrade's auto tests there will not be line breaks after the inputs.
Save: Save your code as main.cpp
. Do not ignore this step or save your file(s) with different names.
Submit: Your program source code must be submitted via CodeGrade as a properly named .cpp
file prior to the deadline to receive full credit. Any submissions after the deadline will be subject to the class’ late policy.