return value 3221225477

can anyone help me fix my program


#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

int Random(int a) { return (rand() % a); }

class game {
public:
string player_name, steel, silver;
int stlatk, silatk;
void set_val(string a, string b, string c, int d, int e) { player_name = a; steel = b; silver = c; stlatk = d; silatk = e; }
virtual void caldmg() {}
virtual void swordstat() {}
};

class dmg : public game {
public:
virtual void caldmg() {
cout << "Damage from steel sword" << (stlatk*(Random(1))) << endl;
cout << "Damage from silver sword" << (stlatk*(7 + (Random(3))) / 10) << endl;
}
};

class crtdmg :public game {
public:
virtual void caldmg() {
cout << "Critical damage from steel sword" << ((stlatk*(Random(1))) * 3) << endl;
cout << "Critical damage from silver sword" << ((stlatk*(7 + (Random(3))) / 10) * 3) << endl;
}
};

class steelsword : public game {
public:
virtual void swordstat() {
cout << "Steel sword name : " << steel << endl;
cout << "Steel sword attack : " << stlatk << endl;
}
};

class silversword : public game {
public:
virtual void swordstat() {
cout << "Silver sword name : " << silver << endl;
cout << "Silver sword attack : " << silatk << endl;
}
};

int main() {
game *p1;
dmg Dmg;
crtdmg Cdmg;
steelsword Stlswd;
silversword Silswd;
string namestl, namesil, pname;
int attack, attack1;
cout << "Input your player name : "; cin >> pname;
cout << endl << "Input your steel sword name : "; cin >> namestl;
cout << "Input your steel sword attack : "; cin >> attack;
cout << endl << "Input your silver sword name : "; cin >> namesil;
cout << "Input your silver sword attack : "; cin >> attack1;
p1->set_val(pname, namestl, namesil, attack, attack1);
cout << p1->player_name;
p1 = &Dmg; p1->caldmg();
p1 = &Cdmg; p1->caldmg();
p1 = &Stlswd; p1->swordstat();
p1 = &Silswd; p1->swordstat();
}
Last edited on
p1 is uninitialized when you call set_val.
Last edited on
ok thx
Last edited on
Topic archived. No new replies allowed.