Some help needed with program.

This is a discussion on Some help needed with program. within the C++ Programming forums, part of the General Programming Boards category; Ive been working on this program that is meant to battle to Fighters. The Fighters are created from the FIGHTER ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    21

    Some help needed with program.

    Ive been working on this program that is meant to battle to Fighters. The Fighters are created from the FIGHTER class and fed into an array. This is array is then fed into FightFunction, which does all the work. The program appears to be fine except for the fact that everytime the function tries to use one of the Get class methods I get:

    "FIGHT2.cpp": E2235 Member function must be called or its address taken in function FightFunction(FIGHTER *) at line 69

    I'm really not sure what the problem is, so any help would be greatly appreciated.

    Here is the code:

    Code:
    #include <iostream>
    using namespace std;
    
    class FIGHTER
    {
      public:
         FIGHTER();
         ~FIGHTER() { };
         void SetWEAPON(int weaponlevel) { WEAPON = weaponlevel; }
         void SetARMOUR(int armourlevel) { ARMOUR = armourlevel; }
         void SetHP(int hp) { HP = hp; }
         int GetWEAPON() const { return WEAPON; }
         int GetARMOUR() const { return ARMOUR; }
         int GetHP() const { return HP; }
      protected:
         int HP;
         int WEAPON;
         int ARMOUR;
    };
    
    FIGHTER::FIGHTER()
    {
      HP = 200;
      WEAPON = 1;
      ARMOUR = 1;
    }
    
    int FightFunction(FIGHTER fighter_array[2]);
    
    int main()
    {
      int result;
      FIGHTER fighter_array[2];
      result = FightFunction(fighter_array);
      switch (result)
      {
      case 1:
        cout << "\n\n\nThe battle was won by player 1";
        break;
      case 2:
        cout << "\n\n\nThe battle was won by player 2";
        break;
      default:
        cout << "\n\n\nNeither player won the battle. Both players died";
        break;
      }
    
    
      cin.ignore();
      cin.get();
      return 0;
    }
    
    int FightFunction(FIGHTER fighter_array[2])
    {
      int random1, random2, winner, r, overallwin;
      cout << "Player 1 has " << fighter_array[0].GetHP << " HP left.";
      cout << "player 2 has " << fighter_array[1].GetHP << " HP left.";
      srand( (unsigned)time( NULL ) );
      r = 1;
      do
        {
        cout << "This is round " << r << ". ";
        random1 = (rand() % 3) + 1;
        random2 = (rand() % 3) + 1;
        if (random1 > random2)
        {
          winner = 1;
          if (fighter_array[0].GetWEAPON > fighter_array[1].GetARMOUR)
          {
            fighter_array[1].SetHP(
            fighter_array[1].GetHP()
            - (20 + ((rand() % (fighter_array[0].GetWEAPON - fighter_array[1].GetARMOUR)) + 1)));
    
            fighter_array[0].SetHP(
            fighter_array[0].GetHP()
            - ((rand() % 5) + 1));
          }
          else if (fighter_array[0].GetWEAPON < fighter_array[1].GetARMOUR)
          {
           fighter_array[1].SetHP(
           fighter_array[1].GetHP()
           - (10 + (rand() % 5) + 1));
    
           fighter_array[0].SetHP(
           fighter_array[0].GetHP()
           - ((rand() % 5) + 1));
          }
          else if (fighter_array[0].GetWEAPON == fighter_array[1].GetARMOUR)
          {
            fighter_array[0].SetHP(
            fighter_array[0].GetHP()
            - ((rand() % 5) + 1));
    
            fighter_array[1].SetHP(
            fighter_array[1].GetHP()
            - (15 + (rand() % 5) + 1));
          }
        }
        else if (random2 > random1)
        {
          winner = 2;
          if (fighter_array[1].GetWEAPON > fighter_array[0].GetARMOUR)
          {
            fighter_array[0].SetHP(
            fighter_array[0].GetHP()
            - (20 + ((rand() % (fighter_array[1].GetWEAPON - fighter_array[0].GetARMOUR)) + 1)));
    
            fighter_array[1].SetHP(
            fighter_array[1].GetHP()
            - ((rand() % 5) + 1));
          }
          else if (fighter_array[1].GetWEAPON < fighter_array[0].GetARMOUR)
          {
            fighter_array[0].SetHP(
            fighter_array[0].GetHP()
            - (10 + (rand() % 5) + 1));
    
            fighter_array[1].SetHP(
            fighter_array[1].GetHP()
            - ((rand() % 5) + 1));
          }
          else if (fighter_array[1].GetWEAPON == fighter_array[0].GetARMOUR)
          {
            fighter_array[0].SetHP(
            fighter_array[0].GetHP()
            - (15 + (rand() % 5) + 1));
    
            fighter_array[1].SetHP(
            fighter_array[1].GetHP()
            - ((rand() % 5) + 1));
          }
        }
        else if (random1 == random2)
        {
          winner = 0;
          fighter_array[0].SetHP(
          fighter_array[0].GetHP()
          - ((rand() % 5) + 1));
    
          fighter_array[1].SetHP(
          fighter_array[1].GetHP()
          - ((rand() % 5) + 1));
        }
    
        switch (winner)
        {
          case 1:
          cout << "\n\nThe winner of round " << r << " is Player 1.";
          cout << "\n\nPlayer 1 has " << fighter_array[0].GetHP << " left.";
          cout << "\n\nPlayer 2 has " << fighter_array[1].GetHP << " left.";
          break;
          case 2:
          cout << "\n\nThe winner of round " << r << " is Player 2.";
          cout << "\n\nPlayer 1 has " << fighter_array[0].GetHP << " left.";
          cout << "\n\nPlayer 2 has " << fighter_array[1].GetHP << " left.";
          break;
          case 0:
          cout << "\n\nRound " << r << " was a stalemate";
          cout << "\n\nPlayer 1 has " << fighter_array[0].GetHP << " left.";
          cout << "\n\nPlayer 2 has " << fighter_array[1].GetHP << " left.";
          break;
        }
        r++;
        } while (fighter_array[0].GetHP > 0 && fighter_array[1].GetHP > 0);
    
      cout << "\n\nThe battle is over!";
      if (fighter_array[1].GetHP <= 0 && fighter_array[0].GetHP > 0)
      overallwin = 1;
      else if (fighter_array[0].GetHP <= 0 && fighter_array[1].GetHP > 0)
      overallwin = 2;
      else if (fighter_array[0].GetHP <= 0 && fighter_array[1].GetHP <= 0)
      overallwin = 0;
    
      return overallwin;
    }
    Thanks in advance.

  2. #2
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    it should be GetWEAPON() not GetWEAPON....everywhere you are doing the same mistake in every call...also u need to include <ctime>

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    21
    Damn it! 4th stupid mistake in 2 weeks, when will I learn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help needed with program - urgent thanks!
    By lildevil in forum C Programming
    Replies: 1
    Last Post: 03-09-2008, 06:45 AM
  2. Drawing program architecture - information needed
    By Marko_D in forum Windows Programming
    Replies: 1
    Last Post: 11-28-2003, 06:46 PM
  3. redirection program help needed??
    By Unregistered in forum Linux Programming
    Replies: 0
    Last Post: 04-17-2002, 05:50 AM
  4. Program Ideas Needed
    By pkananen in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 09:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21