Sign in to follow this  

C++ Help for me

This topic is 2004 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, i'm have to say i'm very, very bad at programming so far but i'm trying to learn, so far i have been trying to make some text based games (no graphics) and so far i haven't gotten anything to work yet -_- i know the solution is easy but still can someone help me? and yes i could improve it but still [img]http://public.gamedev.net//public/style_emoticons/default/dry.png[/img] just in advance thank you
[CODE]
#include <iostream>
using namespace std;
class monster {
// These are private
int health; // health of monster
int damagedelt; // damage of general monsters
int speed; // speed of general monsters
int defence; // defence of general monsters
public:
monster(int h, int dd, int s, int d) {
health = h;
damagedelt = dd;
speed = s;
defence = d;
}
// accessor functions.
int get_health() { return health; }
int get_damagedelt() { return damagedelt; }
int get_speed() { return speed; }
int get_defence() { return defence; }
};
class wolf:public monster {
int speedplus; // wolf has increased speed
public:
// construct for wolf
wolf(int h, int dd, int s, int d, int sp) : monster(h, dd, s, d)

{
speedplus = sp;
}
int truespeed() { return get_speed() + speedplus; }
//accessor function for speed
int get_speedplus() { return speedplus; }
};
class jelly:public monster {
int defenceplus; // extra defence
public:
// construct for jelly
jelly(int h, int dd, int s, int d, int dp) : monster(h, dd, s, d)
{
defenceplus = dp;
}
int truedefence() { return get_defence() + defenceplus; }
// accessor function for defence
int get_defenceplus() { return defenceplus; }
};
class dragon:public monster {
int damagedeltplus;
public:
dragon(int h, int dd, int s, int d, int ddp) : monster(h, dd, s, d)
{
damagedeltplus=ddp;
}
int truedamage() { return get_damagedelt() + damagedeltplus; }
int get_damagedeltplus() { return damagedeltplus; }
};

class me {
// These are private
int health; // health of me
int damagedelt; // damage of me
int spelldelt; // damage of spells
int speed;
int defence;
public:
me(int h, int dd, int sd, int s, int d) {
health = h;
damagedelt = dd;
spelldelt = sd;
speed = s;
defence = d;
}

//accessor function
int get_health() { return health; }
int get_damagedelt() { return damagedelt; }
int get_spelldelt() { return spelldelt; }
int get_speed() { return speed; }
int get_defence() { return defence; }
};
// class declareation for rouge
class rouge:public me {
int speedplus;
public:
rouge(int h, int dd, int sd, int s, int d, int sp) : me(h, dd, sd, s , d) {
speedplus = sp;
}
int truespeed() { return get_speed() + speedplus; }
int get_speedplus() { return speedplus; }
};
//class declareation for paladin
class paladin:public me {
int damageplus;
public:
paladin(int h, int dd, int sd, int s, int d, int dp) : me(h, dd, sd, s, d) {
damageplus = dp;
}
int truedamage() { return get_damagedelt() + damageplus; }
int get_damageplus() { return damageplus; }
};

// class declareation for mage
class mage:public me {
int spellplus;
public:
mage(int h, int dd, int sd, int s, int d, int sp) : me(h, dd, sd, s, d) {
spellplus = sp;
}
int truespell() { return get_spelldelt() + spellplus; }
int get_spellplus() { return spellplus; }
};
int main()
{
int c;
rouge(200, 40, 25, 50, 50, 50);
mage(150, 30, 50, 50, 50, 30);
paladin(300, 50, 25, 50, 50, 30);
cout << "which class do you want to choose? rouge mage or paladin? 1, 2, 3: ";
do {
cin >> c;
switch (c) {
case '1':
cout << "you are the dark rouge who sneaks around at night stalking his pray\n";
break;
case '2':
cout << "you are the powerful mage who has the power to decimate all\n";
break;
case '3':
cout << "you are the proud paladin who will stop at nothing to take down his enemy with brute force\n";
break;

default: cout << "Please pick your selection out of 1 (rouge) 2 (mage) 3 (paladin)?\n";
}
}
while (c<0, c>4);
cout << " you are now ready for your big adventure, have fun";

return 0;
}
[/CODE]

I don't know why but for some reason when i try and run this program it doesn't pick up the number you have put in, however if you do one of the right numbers it skips the part its suppose to say and goes straight to the end, any help?

Share this post


Link to post
Share on other sites
[color=#000088]while[/color][color=#000000] [/color][color=#666600]([/color][color=#000000]c[/color][color=#666600]>[/color][color=#006666]0[/color][color="#666600"] &&[/color][color=#000000] c[/color][color=#666600]<[/color][color=#006666]4[/color][color=#666600]);[/color]


L. Spiro

Share this post


Link to post
Share on other sites
Thank you [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] yeah i'm not very good yet [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] hoping to get better soon at least [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites
[quote name='RulerOfNothing' timestamp='1339838905' post='4949743']
Also, c is an int so you want the cases to be 1,2,3 and not '1','2','3'. This is because in C++ characters are technically integral types and they can be implicitly converted to ints (so it was comparing c to 49,50 and 51 rather than 1,2 and 3)
[/quote]
While this is true, it would be better design to handle the characters that are input (ie. declare '[font=courier new,courier,monospace]c[/font]' as type [font=courier new,courier,monospace]char[/font]). That way, additional cases could be added for commands such as 'n', 'e', 's', or 'w' to move in cardinal directions for example. Confisingly, the [font=courier new,courier,monospace]char[/font] type is also an integral type, but unlike [font=courier new,courier,monospace]operator>>(istream, int)[/font], [font=courier new,courier,monospace]operator>>(istream, char)[/font] does not perform string-to-integer conversion.

Share this post


Link to post
Share on other sites

This topic is 2004 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this