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:
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
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.
#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