Feb 26, 2012 at 11:14pm UTC
I expect the program to run and say this...
My name is Bob! FEAR ME!
I have 100 health!
I can move at 5 MILES PER HOUR!!!
======================================
But I get this.
===================================
My name is ! FEAR ME!
I have -858993460 health!
I can move at -858993460 MILES PER HOUR!!!
Here is the code
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#include <iostream>
#include <string>
#include "BasicMathFunctions.h" //this is not needed.
#include "Measages.h"
using namespace std;
class Warrior{
private :
string name;
int health;
int speed;
public :
void setname(string setname);
string getname();
void sethealth(int sethealth);
int gethealth();
void setspeed(int setspeed);
int getspeed();
void boast();
};
void Warrior::setname(string setname){
setname = name;
};
string Warrior::getname(){
return name;
};
void Warrior::sethealth(int sethealth){
sethealth = health;
};
int Warrior::gethealth(){
return health;
};
void Warrior::setspeed(int setspeed){
setspeed = speed;
};
int Warrior::getspeed(){
return speed;
};
void Warrior::boast(){
cout << "My name is " << getname() << "! FEAR ME! " << endl;
cout << "\nI have " << gethealth() << " health! \n" ;
cout << "I can move at " << getspeed() << " MILES PER HOUR!!!\n" ;
};
int main()
{
Warrior Bob;
Bob.setname("Bob" );
Bob.sethealth(100);
Bob.setspeed(5);
Bob.boast();
pause();//a function that pauses the program. (from Measages.h)
};
Last edited on Feb 26, 2012 at 11:16pm UTC
Feb 26, 2012 at 11:20pm UTC
So name = setname?
ill try. Worked, thank you.
Last edited on Feb 26, 2012 at 11:21pm UTC
Feb 28, 2012 at 7:32pm UTC
This was a really dumb mistake dude. And wats up with all the public and private stuff? Wat does it do? And the :: in the modules wat is that?
Feb 28, 2012 at 9:51pm UTC
he can explain it to me when i see him, will be way better