C++ Lab: OSRS Magic Max Hit Table

Thu Aug 14 2025
Updated: Fri Aug 15 2025
Facebook share linkTwitter/X share linkLinkedIn share linkReddit share linkReddit share link

Purpose

This lab introduces you to using <iomanip> and <cmath> in C++ for output formatting and mathematical computation. You will write a program that calculates magic max hit values in Old School RuneScape, organizing the results into a neatly formatted table using output manipulators like setw, setfill, and justification directives (left, right).

Beyond this example, the same skills apply in real-world programming careers, especially in game development. Designers and analysts often need to generate and present tables of stats—damage values, probability charts, or balancing metrics—for their team leads or bosses. Mastering formatted output now gives you the ability to clearly communicate complex calculations later in a professional setting.


Task

You will:

  1. Prompt the user to enter their Magic level (integer) and Magic bonus (integer).
  2. For multiple spells, calculate max hit using the given formula.
  3. Display the results in a formatted table with aligned columns showing spell name, base damage, Magic level, Magic bonus, and max hit.

Use the magic max hit formula to compute max hits:

Max Hit=Base Damage×(1+Magic Level100)×1+Magic Bonus100\text{Max Hit} = \left\lfloor \text{Base Damage} \times \left(1 + \frac{\text{Magic Level}}{100}\right) \times \sqrt{1 + \frac{\text{Magic Bonus}}{100}} \right\rfloor

Use these spells and base damage values:

SpellBase Damage
Fire Bolt12
Fire Blast16
Fire Wave20

Steps to Complete the Lab

  1. Prompt the user to enter their Magic level and Magic bonus, and read them into integer variables.
  2. For each spell compute the max hit using the formula and table of spells above.
  3. Display a formatted table with headers:
    • Spell: left-justified in 13 spaces.
    • Base Damage: left-justified in 11 spaces.
    • Magic Level: left-justified in 8 spaces.
    • Magic Bonus: right-justified in 5 spaces.
    • Max Hit: right-justified in 9 spaces.

Criteria for Success

See CodeGrade

Example Program Interaction

Enter your Magic level: 70 Enter your Magic bonus: 25 Spell BaseDmg Level Bonus MaxHit ---------------------------------------------- Fire Bolt 12 70 25 22 Fire Blast 16 70 25 30 Fire Wave 20 70 25 38

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.


Submission Instructions

  1. Save: Save your code as main.cpp. Do not ignore this step or save your file(s) with different names.

  2. 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.