Please Help meeeee!!!!!

Guys, i have spent 2 whole days on this program and I just cant get it to work correctly.

So it compiles just fine but I cant get the right output to the values i am seeking.

Please help me :
==============================================================================

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cstddef>
using namespace std;

class Random {
public:
Random(int low, int high); //constructor
int get(void) const;
private:
int low;
int diff;
static void seed(void);
static int seedcount;
};

int Random::seedcount=0;

void Random::seed(void)
{
if(seedcount) return; //we only want to seed once
seedcount=1;
srand((int)time(0)); //seeds the random number generator
}

Random::Random(int l, int h) : low(l), diff(abs(h-l)+1)
{
seed();
}

int Random::get(void) const
{
return int((float)rand()/RAND_MAX*diff+low);
}


class weapon
{
private:
string type;
int hit_chance;
int stamina_required;

public:
weapon();
weapon(string,int,int);
void display();
int display_stamina();
bool did_you_hit();
};

bool weapon::did_you_hit()
{
Random r1(1,100);
if(r1.get()<=hit_chance){return true;}
else{return false;}
}

weapon::weapon(string t,int x, int y):type(t), hit_chance(x), stamina_required(y){}// initilization list

weapon::weapon(){}

void weapon::display()
{
cout<< "weapon type: "<<type<<endl;
cout<< "hit chance: "<<hit_chance<<endl;
cout<< "stamina required "<<stamina_required<<endl;
}
int weapon::display_stamina()
{
return stamina_required;
}

//=====================================================================
//=====================================================================
class knight
{
private:
string name;
int stamina;
bool on_horse;

public:

knight();
knight(string,int,bool);
int stamina_remaining();
bool are_you_exhuasted();
void display();
};
int knight::stamina_remaining()
{ weapon r;
stamina=stamina-(r.display_stamina());
return stamina;
}

bool knight::are_you_exhuasted()
{
if(stamina<=0){on_horse=false;}
else{on_horse=true;}
}
knight::knight(string n, int s, bool x): name(n), stamina(s), on_horse(x){}
knight::knight(){}

void knight::display()
{
cout<< "Knight stamina remaining "<<stamina<<endl;
cout<< "on horse "<<on_horse<<endl;
cout<< "name= "<<name<<endl;
weapon rt;
rt.display();
}
//=======================================================================
//=======================================================================



int main()
{
string weapon_type1,weapon_type2,name1,name2,f;
int hc1,hc2,sr1,sr2,stamina1,stamina2;

cout << "What is the first knights name?" << endl;
cin>> name1;
cout << "What is " << name1 << " stamina?" << endl;
cin>>stamina1;
cout << "What is "<<name1<<" weapon?" << endl;
cin>> weapon_type1;
cout << "What is the weapon's hit chance?" << endl;
cin>> hc1;
cout << "What is the weapon's stamina required to use?" << endl;
cin >> sr1;
cout << "What is the second knights name?" << endl;
cin>> name2;
cout << "What is " << name2 << " stamina?" << endl;
cin>>stamina2;
cout << "What is "<<name2<<" weapon?" << endl;
cin>> weapon_type2;
cout << "What is the weapon's hit chance?" << endl;
cin>> hc2;
cout << "What is the weapon's stamina required to use?" << endl;
cin >> sr2;
weapon w1(weapon_type1,hc1,sr1);
weapon w2(weapon_type2,hc2,sr2);
knight k1(name1, stamina1, true);
knight k2(name2, stamina2, true);

cout<<"Press any key to begin the Joust"<<endl;
cin>>f;
do
{
if(w1.did_you_hit()==true){cout<<"knight 2 is off the horse"<<endl;}
if(w2.did_you_hit()==true){cout<<"knight 1 is off the horse"<<endl;}
if(k1.stamina_remaining()<=0){cout<<"knight 1 is exhausted"<<endl;}
if(k2.stamina_remaining()<=0){cout<<"knight 2 is exhausted"<<endl;}
cout<<"=============================="<<endl;
knight cool;
cool.display();
}
while(k1.stamina_remaining()>0 && k2.stamina_remaining()>0 && w1.did_you_hit()==false && w2.did_you_hit()==false);
return 0;
}

so i guess no help???
It's been an hour. Try putting your code in code tags- it might make it a bit easier to read.
so i guess no help???
Saw the original post. No code tags so there is no indentation. So the code is not readable.

You said with the original
I cant get the right output to the values i am seeking
Then you gave no indication of what output you are getting and no indication of what output you are expecting.

Then the code I can see uses features that I am not as good as others around here. So I chose to look at other threads with my free time.
Last edited on
Topic archived. No new replies allowed.