Thread: Debugging help

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    19

    Debugging help

    I'll mark where errors are coming up..

    Code:
    #include<iostream>
    #include<string>
    #include<cstdlib>
    #include<ctime>
    
    using namespace std;
    
    void Seed()
    {
    	srand(time(0));
    }
    
    int GetRandNum(int max)
    {
     return rand() % max + 1;
    }
    
    class Soldier
    {
    public:
    	Soldier(string input);
    	int March();
    	int Fire();
    	void Rest();
    	void LoseStamina(int distance);
    	void Reload();
    	void LoseAmmo(int shots);
    	void DisplayStats();
    
    
    protected: 
    	string m_name;
    	int m_ammo;
    	int m_maxAmmo;
    	int m_stamina;
    	int m_maxStamina;
    };
    
    
    
    Soldier::Soldier(string input)
    {
    	m_name = input;
    	m_stamina = 50;
    	m_maxStamina = m_stamina;
    	m_ammo = 20;
    	m_maxAmmo = m_ammo;
    }
    
    int Soldier::March()
    {
    	return GetRandNum(10);
    }
    
    int Soldier::Fire()
    {
    	return GetRandNum(4);
    }
    
    void Soldier::Rest()
    {
    	m_stamina = m_maxStamina;
    }
    
    void Soldier::Reload()
    {
    	m_ammo = m_maxAmmo;
    }
    
    void Soldier::LoseStamina(int distance)
    {
    	m_stamina -= distance;
    
    	cout << m_name << " you marched " << distance <<  " miles, you lose " << distance << " stamina " << endl;
    
    	if(m_stamina <= 0)
    		cout << m_name << " can't move " << endl;
    	
    	
    }
    
    void Soldier::LoseAmmo(int shots)
    {
      m_ammo -= shots;
    
      cout << m_name << " you shot " << shots << " bullets " << endl;
    
      if (m_ammo <=0)
    	  cout << m_name << " is out of ammo " << endl;
    }
    
    void Soldier::DisplayStats()
    {
    	cout << "Name: " << m_name << endl;
    	cout << "Stamina: " << m_stamina << "/" << m_maxStamina << endl;
    	cout << "Ammo: " << m_ammo << "/" << m_maxAmmo << endl;
    		
    }
    
    class Scout :  public Soldier
    {
          public:
                 Scout(string input);
                 void LoseStamina(int distance);
          private:
                  int m_stamina;
    	          int m_maxStamina;
                  int m_ammo;
                  int m_maxAmmo;
          };
    Scout::Scout(string input)
          {        right here it's saying no matching function to call to Soldier:: Solider 
          m_name = input;              
          m_stamina = 100;
          m_maxStamina = m_stamina;              
          m_ammo = 5;
         m_maxAmmo = m_ammo;
      }
          void Scout::LoseStamina(int distance);  void lose stam outside of class is not definition
          {
          	m_stamina -= distance/2;
    
    	cout << m_name << ", you lost " << distance << " stamina " << endl;
    
    	if(m_stamina <= 0)
    		cout << m_name << " can't move " << endl;
               
          }
    
    class Machiner : public soldier
    {
          public:
                 Machiner();
                 void LoseStamina(int distance);
                 void LoseAmmo(int shots);
          private:
                  int m_stamina;
                  int m_maxStamina;
    	          int m_ammo;
    	          int m_maxAmmo;
               };
          Machiner::Machiner()
          {
             m_stamina = 25;
             m_maxStamina = m_stamina;
             m_ammo = 100;
             m_maxAmmo = m_ammo;
             }
          void Machiner::LoseStamina(int distance);
                {
          	m_stamina -= distance * 2;
    
    	cout << m_name << ", you lost " << distance << " stamina " << endl;
    
    	if(m_stamina <= 0)
    		cout << m_name << " can't move " << endl;
           }
           
           void Machiner::LoseAmmo(int shots);
    {
      m_ammo -= shots * 4;
    
      cout << m_name << " you shot " << shots << " bullets " << endl;
    
      if (m_ammo <=0)
    	  cout << m_name << " is out of ammo " << endl;
    }
    
    
    class Sniper : public Soldier
    {
          public:
                 Sniper();
                 void LoseAmmo(int shots);
         
         }
          Sniper::Sniper()
          {
          };
          
          void Sniper::LoseAmmo(int shots);
      {
      m_ammo - 1;
    
      cout << m_name << " you shot " << shots << " bullets " << endl;
    
      if (m_ammo <=0)
    	  cout << m_name << " is out of ammo " << endl;
    }

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Code:
    Scout::Scout(string input)
    Since "Scout" extends "Soldier", to create a "Scout", the parents constructor must be called. So its implicitly calling "Soldier()" to create an instance, but this no-arg constructor doesnt exist. Either add this no arg constructor, or do something like
    Code:
    Scout::Scout(string input) : Solder(input)
    Next:
    Code:
          void Scout::LoseStamina(int distance);  void lose stam outside of class is not definition
    Hopefully its obvious enough: remove the semicolon.

    I think both of these things appear a number of times in your code, so try and find them.

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    19
    thanks found them all

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Do not mix tabs and spaces. It's the reason why your code looks messed up here.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dev-C++: Problems with Breakpoint Debugging
    By Thileepan_Bala in forum C Programming
    Replies: 1
    Last Post: 01-17-2008, 10:48 AM
  2. Debugging Dev C++
    By tuurb046 in forum Tech Board
    Replies: 10
    Last Post: 08-16-2007, 12:51 PM
  3. Debugging book recommendation
    By dagans in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 09-13-2005, 07:35 PM
  4. debugging directx apps
    By confuted in forum C++ Programming
    Replies: 1
    Last Post: 08-16-2003, 08:56 AM
  5. Debugging mode selection during compile time
    By YALINI in forum C Programming
    Replies: 1
    Last Post: 09-03-2001, 09:56 AM