cout doesnt show
Mar 27, 2015 at 9:46pm UTC
Not sure if this is the best way to write a combat engine but its my go at it using classes. But I cannot cout the heros hp and creatures hp for whatever reason in class match. I'm not even sure if this code is making it that far and everytime i change it to something different it gives a error about having a semi colon or a parenthesis behind creaturestr but obviously that needs to be couted as well. But it isn't showing me that cout either.
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
#include <iostream>
#include <string>
using namespace std;
string x;
int herolvl = 1;
int herohp = herolvl + 19;
int herostr = herolvl + 4;
int creaturehp = (herolvl + 4);
int creaturestr = (herolvl + 4);
class attack{
public :
void match(){
cout<<"herohp creaturehp" ; \\ this does not show when ran.
int (herohp - creaturestr);
int (creaturehp - herostr);
}
};
class encounter{
public :
void battle(){
cout<<"You have encountered a creature, attack or run." ;
cin>>x;
getline(cin, x);
cin.ignore();
if (x == "attack" ){
attack bev;
bev.match();
}
else if (x == "run" ){
}
}
};
int main(){
encounter fight;
fight.battle();
}
Last edited on Mar 27, 2015 at 9:55pm UTC
Mar 27, 2015 at 9:53pm UTC
Lets see...
First of all.
\\ this does not show when ran. // not \\
Second.
1 2
cin>>x;
getline(cin, x);
uhm... Why are you using both cin and getline to input x? You only need one of them... remove the getline, and the
cin.ignore();
and you're done.
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
string x;
int herolvl = 1;
int herohp = herolvl + 19;
int herostr = herolvl + 4;
int creaturehp = (herolvl + 4);
int creaturestr = (herolvl + 4);
class attack{
public :
void match(){
cout << "herohp creaturehp" << endl; // this does not show when ran.
}
};
class encounter{
public :
void battle(){
cout << "You have encountered a creature, attack or run." ;
cin >> x;
if (x == "attack" ){
attack bev;
bev.match();
}
else if (x == "run" ){
}
}
};
int main(){
encounter fight;
fight.battle();
system("pause" );
}
Last edited on Mar 27, 2015 at 9:54pm UTC
Topic archived. No new replies allowed.