Jump to content

  • Log In with Google      Sign In   
  • Create Account

Big T06

Member Since 16 Jun 2012
Offline Last Active Oct 21 2014 05:52 PM

Topics I've Started

C++ not initilizing

05 July 2012 - 09:07 AM

i only have one problem and i have one problem why its not working, and i can't figure out what is wrong
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Hello everyone and welcome to this game.\n";
cout << "In this game the aim is to attack the wolf with what you think is the best attack, goodluck!\n";
int healthme=500;
int healthit=500;
while(healthme>0 && healthit>0 ) {
  cout << "Your Health is " << healthme << " and the wolfs health is " << healthit << "\n";
  cout << "So, what attack do you want to hit the wolf with a weapon or with magic?";
  string attack;
  cin >> attack;

  if (attack.find("weapon") != std::string::npos) {
   cout << "What part of the wolf do you want to attack, the body or the head?\n";
   string bodypart;
   cin >> bodypart;
   if(bodypart.find("body") != std::string::npos) {
    healthit-= getdamage(50, 10);
    cout << "You hit the wolf!\n";
    }
   
   else if(bodypart.find("head") != std::string::npos) {
    healthit -= getdamage(100, 20);
    healthme -= getdamage(20, 5);
    cout << "It was a good hit, but it bites back!\n";
    }

   else cout << "you missed! (spelt it wrong) \n";
   }
  else if (attack.find("magic") != std::string::npos){
   cout << "what element would you like to attack with? fire lightning, ice, water, or earth?\n";
   string magic;
   cin >> magic;
   if(magic == "fire"){
    healthit-= getdamage(50, 10);
    cout << "It does good damage!\n";
    }
   else if(magic == "lightning"){
    healthit-= getdamage(100, 10);
    cout << "It does amazing damage!\n";
    }
   
    else if(magic == "earth"){
    healthit-= getdamage(70, 10);
    cout << "It hits hard!\n";
    }
   else if(magic=="ice") {
    healthit -= getdamage(30, 5);
    cout << "It doesn't seem to hurt much!\n";
    }
   else if(magic=="water") {
    healthit -= getdamage(10, 2);
    cout << "It seems unaffected!\n";
    }
   else cout << "You missed! (spelt it wrong!)\n";
   }
  else cout << "you took to long! (spelt wrong!)";
  if(healthit>=0){
   if(healthit<=100){
  
    cout << "He is Angry now and doing more damage!\n";
    healthme -= getdamage(75, 10);
    }
   else {
    cout << "The wolf goes out to attack!\n";
    healthme-= getdamage(50, 10);
    }
  }
}
if(healthme<=0) cout << "Your Dead... Game over i guess?";
else cout << "The wolf is dead! You Win!";
  
return 0;
}
// Returns a random value within DamageRange of Damagebase
int getdamage(int damagebase, int damagerange)
{
  // if DamageBase is 50, and DamageRange is 10, DamageBase will be 40 here
  int damagedealt = damagebase - damagerange;
  // if DamageRange is 10, then this will add anywhere from 0 to 20 damage*
  damagedealt += (rand() % (damagerange*2));
  return damagedealt;
}
  
   

when compiling the program the error
'getdamage' identifier not found
i can't figure out whats wrong its probably something stupid but still thanks for any help anyway Posted Image

Improvements on a game

03 July 2012 - 06:59 AM

Hello Everyone i am just wondering if i can get some tips on how i could improve on my code that i have done, i know that some parts could be redone but i just want to know what parts i could make better

#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Hello everyone and welcome to this game.\n";
cout << "In this game the aim is to attack the wolf with what you think is the best attack, goodluck!\n";
int healthme=500;
int healthit;
for(healthit=500 ;healthme>0 && healthit>0; ) {
  cout << "Your Health is " << healthme << " and the wolfs health is " << healthit << "\n";
  cout << "So, what attack do you want to hit the wolf with a weapon or with magic?";
  string attack;
  cin >> attack;

  if (attack.find("weapon") != std::string::npos) {
   cout << "What part of the wolf do you want to attack, the body or the head?\n";
   string bodypart;
   cin >> bodypart;
   if(bodypart.find("body") != std::string::npos) {
	healthit=healthit-50;
	cout << "You hit the wolf!\n";
	}
  
   else if(bodypart.find("head") != std::string::npos) {
	healthit = healthit-100;
	healthme=healthme-20;
	cout << "It was a good hit, but it bites back!\n";
	}

   else cout << "you missed! (spelt it wrong) \n";
   }
  else if (attack.find("magic") != std::string::npos){
   cout << "what element would you like to attack with? fire lightning, ice, water, or earth?\n";
   string magic;
   cin >> magic;
   if(magic == "fire"){
	healthit=healthit-50;
	cout << "It does good damage!\n";
	}
   else if(magic == "lightning"){
	healthit=healthit-100;
	cout << "It does amazing damage!\n";
	}
  
	else if(magic == "earth"){
	healthit= healthit-70;
	cout << "It hits hard!\n";
	}
   else if(magic=="ice") {
	healthit = healthit-30;
	cout << "It doesn't seem to hurt much!\n";
	}
   else if(magic=="water") {
	healthit = healthit - 10;
	cout << "It seems unaffected!\n";
	}
   else cout << "You missed! (spelt it wrong!)\n";
   }
  else cout << "you took to long! (spelt wrong!)";
  if(healthit>=0){
   if(healthit<=100){
  
	cout << "He is Angry now and doing more damage!\n";
	healthme = healthme-75;
	}
   else {
	cout << "The wolf goes out to attack!\n";
	healthme= healthme-50;
	}
  }
}
if(healthme<=0) cout << "Your Dead... Game over i guess?";
else cout << "The wolf is dead! You Win!";
  
return 0;
}
  
  

if you can bother please take the time and tell me what i could make better Posted Image thank you

C++ problems

29 June 2012 - 04:39 AM

Hello everyone i was just wondering what i'm doing wrong with my code, as when i try to compile it comes up with what i describe as code dump, there are a few other problems but once i get the code dump out the way i should be able to fix everything else
#include <iostream>
#include <string>
using namespace std;
int main() {
    cout << "Hello everyone and welcome to this game.\n";
    cout << "In this game the aim is to attack the wolf with what you think is the best attack, goodluck!\n";
    int healthme;
    int healthit;
    for(healthme=500;healthme<0; ); (healthit=500; healthit<0; ) {
	    cout << "Your Health is " << healthme << " and the wolfs health is " << healthit << "\n";
	    cout << "So, what attack do you want to hit the wolf with a weapon or with magic?";
	    string attack;
	    cin >> attack;
   
	    if(attack=="a weapon" , "weapon" , "the weapon") {
		    cout << "What part of the wolf do you want to attack, the body or the head?";
		    string bodypart;
		    cin >> bodypart;
		    if(bodypart == "the body" , "body") {
			    healthit=healthit-50;
			    cout << "You hit the wolf!\n";
			    }
			   
		    else if(bodypart == "the head" , "head") {
			    healthit = healthit-100;
			    healthme=healthme-20;
			    cout << "It was a good hit, but it bites back!\n";
			    }
		    else cout << "you missed! (spelt it wrong) \n";
		    }
	    else if(attack =="magic" , "with magic"){
		    cout << "what element would you like to attack with? fire lightning, ice, water, or earth?\n";
		    string magic;
		    cin << magic;
		    if(magic == "fire"){
			    healthit=healthit-50;
			    cout << "It does good damage!\n";
			    }
		    else if(magic == "lightning"){
			    healthit=healthit-100;
			    cout << "It does amazing damage!\n";
			    }
			   
			    else if(magic == "earth"){
			    healthit= healthit-70;
			    cout << "It hits hard!\n";
			    }
		    else if(magic=="ice") {
			    healthit = healthit-30;
			    cout << "It doesn't seem to hurt much!\n";
			    }
		    else if(magic=="water") {
			    healthit = healthit - 10;
			    cout << "It seems unaffected!\n";
			    }
		    else cout << "You missed! (spelt it wrong!)\n";
		    }
	    else cout << "you took to long! (spelt wrong!)";
	    if(healthit<=100){
		    cout << "He is Angry now and doing more damage!\n";
		    healthme = healthme-75;   
		    }
	    else {
		    cout << "The wolf goes out to attack!\n";
		    healthme= healthme-50;
		    }
	    }
    if(healthme<=0) cout << "Your Dead... Game over i guess?";
    else cout << "The wolf is dead! You Win!";
		   
    return 0;
}

Sorry about the neatness but would be appreciated if someone could tell me what i'm doing wrong, thank you in advance Posted Image

Switch Topic for C++

16 June 2012 - 05:07 AM

Hello I just need some help with getting the switch to read characters instead of numbers, how would i be able to do that because so far when the program compiles the program can't read what i write

C++ Help for me

16 June 2012 - 02:58 AM

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 Posted Image just in advance thank you
#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;
}

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?

PARTNERS