Thread: if statement trouble...I think

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    89

    if statement trouble...I think

    The problem is that the last skill type gets outputted as Master when it should be instead Novice.

    As you can see the skill level of each is zero. Unfortunately I cant figure out why it is doing that. I cant find anything wrong with my if statement. (screenshot is below the code)

    Heres the code:
    Code:
    void CPlayer::SetCurrentSkill(int nSkill)
    {
        switch(nSkill)
        {
            case 0:
                m_CurrentSkill = &m_HandtoHand;
                break;
            case 1:
                m_CurrentSkill = &m_Blade;
                break;
            case 2:
                m_CurrentSkill = &m_Axe;
                break;
            case 3:
                m_CurrentSkill = &m_Blunt;
                break;
        }
    }
    
    void CPlayer::SetSkillName(int nSkill)
    {
        switch(nSkill)
        {
            case 0:
                m_CurrentSkill->s_SkillName = "Hand to Hand";
                break;
            case 1:
                m_CurrentSkill->s_SkillName = "Blade";
                break;
            case 2:
                m_CurrentSkill->s_SkillName = "Axe";
                break;
            case 3:
                m_CurrentSkill->s_SkillName = "Blunt";
                break;
        }
    }
    
    void CPlayer::SetSkillLevel(int nSkill)
    {
        SetCurrentSkill(nSkill);
    
        if (m_CurrentSkill->s_Level < 21)
        {
            m_CurrentSkill->s_SkillLevel = Skills_s::NOVICE;
            m_CurrentSkill->s_SkillAbility = "Novice";
        }
        else if (m_CurrentSkill->s_Level > 20 && m_CurrentSkill->s_Level < 41)
        {
            m_CurrentSkill->s_SkillLevel = Skills_s::APPRENTICE;
            m_CurrentSkill->s_SkillAbility = "Apprentice";
        }
        else if (m_CurrentSkill->s_Level > 40 && m_CurrentSkill->s_Level < 61)
        {
            m_CurrentSkill->s_SkillLevel = Skills_s::SKILLED;
            m_CurrentSkill->s_SkillAbility = "Skilled";
        }
        else if (m_CurrentSkill->s_Level > 60 && m_CurrentSkill->s_Level < 81)
        {
            m_CurrentSkill->s_SkillLevel = Skills_s::PROFESSIONAL;
            m_CurrentSkill->s_SkillAbility = "Professional";
        }
        else
        {
            m_CurrentSkill->s_SkillLevel = Skills_s::MASTER;
            m_CurrentSkill->s_SkillAbility = "Master";
        }
    }
    
    void CPlayer::SetSkills()
    {
        for (int x = 0; x < 4; x++)
        {
            SetCurrentSkill(x);
            SetSkillName(x);
            SetSkillLevel(x);
            m_CurrentSkill->s_Total = 1;
            m_CurrentSkill->s_Increment = 0.2f;
            m_CurrentSkill->s_Level = m_CurrentSkill->s_Increment * m_CurrentSkill->s_Total;
        }
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You call SetSkillLevel before you set the value for m_CurrentSkill->s_Level. Shouldn't you be doing it after?

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    89
    thanks...that fixed the problem...I would never have found it

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by eaane74 View Post
    thanks...that fixed the problem...I would never have found it
    Well that's because you haven't set your skill level to 100 yet

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. Switch statement
    By beene in forum C++ Programming
    Replies: 21
    Last Post: 07-01-2007, 08:13 AM
  3. If statement being ignored?
    By FincH in forum C Programming
    Replies: 3
    Last Post: 04-18-2007, 01:51 PM
  4. having trouble understanding this statement
    By kes103 in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2003, 09:00 AM
  5. string & if statement
    By Curacao in forum C++ Programming
    Replies: 4
    Last Post: 05-02-2003, 09:56 PM