Level up system

I’m working on a level up system, and got a basic function to work. My next step is to create a Character Class and refactor the level up function into a working class method.

int Level_Up( int &exp_gain,  int &current_level)
    {
        bool lv_up;
        int experience_points = 0;
        int total_exp = experience_points + exp_gain;
        int next_exp = 10;
        string leveled_up = "You leveled up to: ";

        if(total_exp >= next_exp)
        {
             lv_up = true;
        }

        if ( lv_up == true)
        {
            current_level++;
            next_exp = next_exp + total_exp * 2;
    
        }

     cout << leveled_up << current_level << "\n";
     cout << "Next Level: " << next_exp << "exp \n";
        return 0;


    }



int main()
{
    int current_level = 1;
    int exp_gain = 50;
    Level_Up(exp_gain, current_level);
    exp_gain = 150;
    Level_Up(exp_gain, current_level);

    return 0;
}```
1 Like

Fantastic job with the level up system!

Privacy & Terms