Any help?

I'm doing a project and one of the assignments includes adding to another.
I had to add two variables to my Weapons class. Here's what I have for my
Weapon.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  1 #ifndef WEAPON_H
  2 #define WEAPON_H
  3 #include <iostream>
  4 #include<string>
  5 using namespace std;
  6 
  7 
  8 class Weapon {
  9     private:
 10              int hit_chance;
 11              int stamina_required;
 12              string weapon;
 13 
 14 
 15     public:
 16           void display(void);
 17           Weapon(string weapon_1, int hit, int stamina);
 18           int get_stamina_required(void);
 19           bool did_you_hit(void);
 20 };
 21 #endif 


Weapon.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  1 #include "Weapon.h"
  2 #include "Random.h"
  3 
  4 Weapon:: Weapon(string weapon_1, int stamina, int hit)
  5   :hit_chance(hit), stamina_required(stamina), weapon(weapon_1)
  6 {
  7 }
  8 void Weapon::display(void)
  9 {
 10   cout << "hit chance=" << hit_chance  << endl;
 11   cout << "stamina required=" << stamina_required  << endl;
 12   cout << "weapon type is" << weapon << endl;
 13 }
 14 
 15 int Weapon::get_stamina_required(void)
 16 {
 17  return stamina_required;
 18 }
 19 
 20 bool Weapon::did_you_hit(void)
 21 {
 22 
 23     if(int get<=hit_chance)
 24 {
 25     hit_chance==true;
 26 }
 27 
 28 else
 29 {
 30 return false;
 31 }
 32 }


assignment11.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  1 #include<iostream>
  2 using namespace std;
  3 
  4 int main()
  5 {
  6  Weapon w1("Lance", 13, 5);
  7  w1.display();
  8  cout << "Stamina required is:" << w1.get_stamina_required()<< endl;
  9  for( int i=0;i<10;++i)
 10    if (w1.did_you_hit())
 11      cout << "The weapon hit!" << endl;
 12    else
 13      cout << "The weapon missed" << endl;
 14  return 0;
 15 }
~       


and my Makefile:
1
2
assignment11: assignment11.cpp Weapon.h Weapon.cpp Random.h Random.cpp
  2     g++ -o assignment11 assignment11.cpp Weapon.cpp Random.cpp


When I try to "make" it, I get this error:
1
2
3
4
5
6
7
8
9
10
make: Warning: File `assignment11.cpp' has modification time 8.1e+02 s in the future
g++ -o assignment11 assignment11.cpp Weapon.cpp Random.cpp
assignment11.cpp: In function 'int main()':
assignment11.cpp:6: error: 'Weapon' was not declared in this scope
assignment11.cpp:6: error: expected ';' before 'w1'
assignment11.cpp:7: error: 'w1' was not declared in this scope
Weapon.cpp: In member function 'bool Weapon::did_you_hit()':
Weapon.cpp:23: error: expected primary-expression before 'int'
Weapon.cpp:23: error: expected ')' before 'int'
make: *** [assignment11] Error 1 


I really can't figure out why and need help!
assignment11.cpp: In function 'int main()':
assignment11.cpp:6: error: 'Weapon' was not declared in this scope
assignment11.cpp:6: error: expected ';' before 'w1'
assignment11.cpp:7: error: 'w1' was not declared in this scope
weapon.h has to be included in assignment11.cpp.

Weapon.cpp: In member function 'bool Weapon::did_you_hit()':
Weapon.cpp:23: error: expected primary-expression before 'int'
Weapon.cpp:23: error: expected ')' before 'int'
What are you trying to do here? This makes no sense.
 
if(int get<=hit_chance)
I'm trying to say
if( int RANDOM NUMBER is less then or equal to hit chance)
Oh, boy.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <ctime> //for time()
#include <cstdlib> //for srand() and rand()

int ranged_rand(int min, int max);

int main(){
    //Seed the PRNG. Call this function ONCE in your program.
    srand(time(0));

    //rand() returns a number between 0 and RAND_MAX, inclusive. A typical
    //value for RAND_MAX is 32767.
    std::cout <<rand()<<std::endl;

    std::cout <<ranged_rand(5,25)<<std::endl;
}

//Returns a random number min <= n <= max.
//Note that max-min+1 <= RAND_MAX has to be true, or the function behaves badly.
int ranged_rand(int min, int max){
    //I won't go into the details of statistical bias and modulo arithmetic,
    //because I could be here all day. For now, just use the function if you
    //need it. Don't worry if you don't understand how it works.
    return rand()%(max-min+1)+min;
}
I already have a random number class so I shouldn't need all that, I'm including in in my makefile
I just don't know what I would include in my code to express it
Sorry, I forgot which board I was posting on.

I just don't know what I would include in my code to express it
If you don't know how to use your own class, who would?
Topic archived. No new replies allowed.