Ok so I decided two nights ago to try and build a simple game like program in the console. No graphics, and nothing special. Everything was going fine until I tried to input the function for the grenades. They were supposed to wipe out 12 "zombies" and reduce the so called HP just a little(about half). It was supposed to be like a watered down COD zombies thing ( In case you can't tell, breaking my last xbox controller has deeply effected my thinking). However, this is hour 6 of me trying to fix this problem and I can't. So please help before I explode!
#include <iostream>
#include <string>
usingnamespace std;
class Weapon
{ public:
int messdemup;
int messdemup2;
int spcl;
};
class Gun
{ public:
int use;
int damage;
};
int main ()
{meh:
int zombies = 100;
int ammo = 100;
int nades = 15;
int health = 150;
Gun smg;
smg.damage = 3;
smg.use = 6;
Gun shotgun;
shotgun.damage = 2;
shotgun.use = 2;
Gun Sniper;
Sniper.damage = 1;
Sniper.use = 1;
string shtgun;
string weapon;
string submg;
char r;
string end;
Weapon knife;
knife.messdemup = 1;
Weapon grenade;
grenade.messdemup = 6;
grenade.messdemup2 = 12;
grenade.spcl = 1;
string sniper;
string begin;
string endturn;
cout << "Welcome to the beginning of the end!\n"<<endl;
cout << "To start your fight against death please type start.\n For help type in help. ";
cin >> begin;
if (begin =="help")
{cout << "This game is very simple. All you have to do is\n A. Eliminate all the zombies\nB. try not to let your health reach zero.\nAnd C. don't runn out of supplies." << endl;
cout << "" << endl;
cout << "Please enter start to begin. ";
cin >> begin;}
check:
cout << "Type in smg to use your sub machine gun, shotgun for your shotgun,\n sniper for your sniper rifle, knife for your knife, and grenade to throw a frag. ";
cin >> weapon;
if (weapon == "smg")
{ int zombieslft = zombies - smg.damage;
zombies = zombieslft;
int ammolft = ammo - smg.use;
ammo = ammolft;
int healthlft = health - smg.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades << " grenades left \nYour health is at " << health << " HP and you still have " << zombieslft << " zombies left to kill.\n Hurry soldier!" << endl;
system("PAUSE");
system ("CLS");
goto check;}
if (weapon == "shotgun");
{int zombieslft = zombies - shotgun.damage;
zombies = zombieslft;
int ammolft = ammo - shotgun.use;
ammo = ammolft;
int healthlft = health - shotgun.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades << " grenades left \nYour health is at " << health << " HP and you still have " << zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;}
if (weapon == "sniper")
{int zombieslft = zombies - Sniper.damage;
zombies = zombieslft;
int ammolft = ammo - Sniper.use;
ammo = ammolft;
int healthlft = health - Sniper.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades << " grenades left \nYour health is at " << health << " HP and you still have " << zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;}
if (weapon == "grenade") // this is the part where the problem most likely occurs
{ int zombieslft = zombies - grenade.messdemup;
zombies = zombieslft;
int nadeslft = nades - 1;
nades = nadeslft;
int healthlft = health - grenade.messdemup;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades << " grenades left \nYour health is at " << health << " HP and you still have " << zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;} // everytime I start this game the grenade kills 3 zombies instead of 12 please help
if (weapon == "knife")
{ int zombieslft = zombies - knife.messdemup;
zombies = zombieslft;
int healthlft = health - knife.messdemup;
cout << "You have : " << ammo << " shots left and " << nades << " grenades left \nYour health is at " << health << " HP and you still have " << zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;}
}
Thanks again for your help!
Kenny
p.s If you put OMG they killed Kenny, I might break my router.
I'm sure that if you fixed your indentation and split long lines onto two or three lines to make it easier to read that you'd have a much, much easier time finding your problem. I'm not going to go through this unindented mess of code when you understand it better than me. If it were indented, it'd be 100% easier to read. You can use two to four spaces or one tab for an indentation.
#include <iostream>
#include <string>
usingnamespace std;
class Weapon
{ public:
int messdemup;
int messdemup2;
int spcl;
};
class Gun
{ public:
int use;
int damage;
};
int main ()
{meh:
int zombies = 100;
int ammo = 100;
int nades = 15;
int health = 150;
Gun smg;
smg.damage = 3;
smg.use = 6;
Gun shotgun;
shotgun.damage = 2;
shotgun.use = 2;
Gun Sniper;
Sniper.damage = 1;
Sniper.use = 1;
string shtgun;
string weapon;
string submg;
char r;
string end;
Weapon knife;
knife.messdemup = 1;
Weapon grenade;
grenade.messdemup = 6;
grenade.messdemup2 = 12;
grenade.spcl = 1;
string sniper;
string begin;
string endturn;
cout << "Welcome to the beginning of the end!\n"<<endl;
cout << "To start your fight against death please type start.\n""For help type in help. ";
cin >> begin;
if (begin =="help")
{cout << "This game is very simple. All you have to do is\n ""A. Eliminate all the zombies\nB. try not to let your health reach zero.\n""And C. don't runn out of supplies." << endl;
cout << "" << endl;
cout << "Please enter start to begin. ";
cin >> begin;}
check:
cout << "Type in smg to use your sub machine gun, shotgun for your shotgun,\n""sniper for your sniper rifle, knife for your knife,"" and grenade to throw a frag. ";
cin >> weapon;
if (weapon == "smg")
{ int zombieslft = zombies - smg.damage;
zombies = zombieslft;
int ammolft = ammo - smg.use;
ammo = ammolft;
int healthlft = health - smg.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades
<< " grenades left \nYour health is at " << health << " HP and you still have "
<< zombieslft << " zombies left to kill.\n Hurry soldier!" << endl;
system("PAUSE");
system ("CLS");
goto check;}
if (weapon == "shotgun");
{int zombieslft = zombies - shotgun.damage;
zombies = zombieslft;
int ammolft = ammo - shotgun.use;
ammo = ammolft;
int healthlft = health - shotgun.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades <<
" grenades left \nYour health is at " << health << " HP and you still have "
<< zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;}
if (weapon == "sniper")
{int zombieslft = zombies - Sniper.damage;
zombies = zombieslft;
int ammolft = ammo - Sniper.use;
ammo = ammolft;
int healthlft = health - Sniper.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades
<< " grenades left \nYour health is at " << health << " HP and you still have "
<< zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;}
if (weapon == "grenade")
{ int zombieslft = zombies - grenade.messdemup;
zombies = zombieslft;
int nadeslft = nades - 1;
nades = nadeslft;
int healthlft = health - grenade.messdemup;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades <<
" grenades left \nYour health is at " << health << " HP and you still have "
<< zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;}
// everytime I start this game the grenade kills 3 zombies instead of 12
if (weapon == "knife")
{ int zombieslft = zombies - knife.messdemup;
zombies = zombieslft;
class="centertext">
int healthlft = health - knife.messdemup;
cout << "You have : " << ammo << " shots left and " << nades <<
" grenades left \nYour health is at " << health << " HP and you still have " <<
zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;}
}
#include <iostream>
#include <string>
usingnamespace std;
class Weapon
{
public:
int messdemup;
int messdemup2;
int spcl;
};
class Gun
{
public:
int use;
int damage;
};
int main ()
{ meh:
int zombies = 100;
int ammo = 100;
int nades = 15;
int health = 150;
Gun smg;
smg.damage = 3;
smg.use = 6;
Gun shotgun;
shotgun.damage = 2;
shotgun.use = 2;
Gun Sniper;
Sniper.damage = 1;
Sniper.use = 1;
string shtgun;
string weapon;
string submg;
char r;
string end;
Weapon knife;
knife.messdemup = 1;
Weapon grenade;
grenade.messdemup = 6;
grenade.messdemup2 = 12;
grenade.spcl = 1;
string sniper;
string begin;
string endturn;
cout << "Welcome to the beginning of the end!\n"<<endl;
cout << "To start your fight against death please type start.\n""For help type in help. ";
cin >> begin;
if (begin =="help")
{ cout << "This game is very simple. All you have to do is\n ""A. Eliminate all the zombies\nB. try not to let your health reach zero.\n""And C. don't runn out of supplies." << endl;
cout << "" << endl;
cout << "Please enter start to begin. ";
cin >> begin;
}
check:
cout << "Type in smg to use your sub machine gun, shotgun for your shotgun,\n""sniper for your sniper rifle, knife for your knife,"" and grenade to throw a frag. ";
cin >> weapon;
if (weapon == "smg")
{ int zombieslft = zombies - smg.damage;
zombies = zombieslft;
int ammolft = ammo - smg.use;
ammo = ammolft;
int healthlft = health - smg.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades
<< " grenades left \nYour health is at " << health << " HP and you still have "
<< zombieslft << " zombies left to kill.\n Hurry soldier!" << endl;
system("PAUSE");
system ("CLS");
goto check;
}
if (weapon == "shotgun");
{ int zombieslft = zombies - shotgun.damage;
zombies = zombieslft;
int ammolft = ammo - shotgun.use;
ammo = ammolft;
int healthlft = health - shotgun.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades <<
" grenades left \nYour health is at " << health << " HP and you still have "
<< zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;
}
if (weapon == "sniper")
{ int zombieslft = zombies - Sniper.damage;
zombies = zombieslft;
int ammolft = ammo - Sniper.use;
ammo = ammolft;
int healthlft = health - Sniper.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades
<< " grenades left \nYour health is at " << health << " HP and you still have "
<< zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;
}
if (weapon == "grenade")
{ int zombieslft = zombies - grenade.messdemup;
zombies = zombieslft;
int nadeslft = nades - 1;
nades = nadeslft;
int healthlft = health - grenade.messdemup;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades <<
" grenades left \nYour health is at " << health << " HP and you still have "
<< zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;
}
// everytime I start this game the grenade kills 3 zombies instead of 12
if (weapon == "knife")
{ int zombieslft = zombies - knife.messdemup;
zombies = zombieslft;
class="centertext">
int healthlft = health - knife.messdemup;
cout << "You have : " << ammo << " shots left and " << nades <<
" grenades left \nYour health is at " << health << " HP and you still have " <<
zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;
}
}
#include <iostream>
#include <string>
usingnamespace std;
class Weapon
{ public:
int messdemup;
int messdemup2;
int spcl;
};
class Gun
{ public:
int use;
int damage;
};
int main ()
{meh:
int zombies = 100;
int ammo = 100;
int nades = 15;
int health = 150;
Gun smg;
smg.damage = 3;
smg.use = 6;
Gun shotgun;
shotgun.damage = 2;
shotgun.use = 2;
Gun Sniper;
Sniper.damage = 1;
Sniper.use = 1;
string shtgun;
string weapon;
string submg;
char r;
string end;
Weapon knife;
knife.messdemup = 1;
Weapon grenade;
grenade.messdemup = 6;
grenade.messdemup2 = 12;
grenade.spcl = 1;
string sniper;
string begin;
string endturn;
cout << "Welcome to the beginning of the end!\n"<<endl;
cout << "To start your fight against death please type start.\n""For help type in help. ";
cin >> begin;
if (begin =="help")
{cout << "This game is very simple. All you have to do is\n ""A. Eliminate all the zombies\nB. try not to let your health reach zero.\n""And C. don't runn out of supplies." << endl;
cout << "" << endl;
cout << "Please enter start to begin. ";
cin >> begin;}
check:
cout << "Type in smg to use your sub machine gun, shotgun for your shotgun,\n""sniper for your sniper rifle, knife for your knife,"" and grenade to throw a frag. ";
cin >> weapon;
if (weapon == "smg")
{ int zombieslft = zombies - smg.damage;
zombies = zombieslft;
int ammolft = ammo - smg.use;
ammo = ammolft;
int healthlft = health - smg.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades
<< " grenades left \nYour health is at " << health << " HP and you still have "
<< zombieslft << " zombies left to kill.\n Hurry soldier!" << endl;
system("PAUSE");
system ("CLS");
goto check;}
if (weapon == "shotgun");
{int zombieslft = zombies - shotgun.damage;
zombies = zombieslft;
int ammolft = ammo - shotgun.use;
ammo = ammolft;
int healthlft = health - shotgun.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades <<
" grenades left \nYour health is at " << health << " HP and you still have "
<< zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;}
if (weapon == "sniper")
{int zombieslft = zombies - Sniper.damage;
zombies = zombieslft;
int ammolft = ammo - Sniper.use;
ammo = ammolft;
int healthlft = health - Sniper.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades
<< " grenades left \nYour health is at " << health << " HP and you still have "
<< zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;}
if (weapon == "grenade")
{ int zombieslft = zombies - grenade.messdemup;
zombies = zombieslft;
int nadeslft = nades - 1;
nades = nadeslft;
int healthlft = health - grenade.messdemup;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades <<
" grenades left \nYour health is at " << health << " HP and you still have "
<< zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;}
// everytime I start this game the grenade kills 3 zombies instead of 12
if (weapon == "knife")
{ int zombieslft = zombies - knife.messdemup;
zombies = zombieslft;
int healthlft = health - knife.messdemup;
cout << "You have : " << ammo << " shots left and " << nades <<
" grenades left \nYour health is at " << health << " HP and you still have " <<
zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;}
}
#include <iostream>
#include <string>
usingnamespace std;
struct Weapon
{
int messdemup;
int messdemup2;
int spcl;
};
struct Gun
{
int use;
int damage;
};
int main ()
{
meh:
int zombies = 100;
int ammo = 100;
int nades = 15;
int health = 150;
Gun smg;
smg.damage = 3;
smg.use = 6;
Gun shotgun;
shotgun.damage = 2;
shotgun.use = 2;
Gun Sniper;
Sniper.damage = 1;
Sniper.use = 1;
string shtgun;
string weapon;
string submg;
char r;
string end;
Weapon knife;
knife.messdemup = 1;
Weapon grenade;
grenade.messdemup = 6;
grenade.messdemup2 = 12;
grenade.spcl = 1;
string sniper;
string begin;
string endturn;
cout << "Welcome to the beginning of the end!\n"<<endl;
cout << "To start your fight against death please type start.\n""For help type in help. ";
cin >> begin;
if (begin =="help")
{
cout << "This game is very simple. All you have to do is\n ""A. Eliminate all the zombies\nB. try not to let your health reach zero.\n""And C. don't runn out of supplies." << endl;
cout << "" << endl;
cout << "Please enter start to begin. ";
cin >> begin;
}
check:
cout << "Type in smg to use your sub machine gun, shotgun for your shotgun,\n""sniper for your sniper rifle, knife for your knife,"" and grenade to throw a frag. ";
cin >> weapon;
if (weapon == "smg")
{
int zombieslft = zombies - smg.damage;
zombies = zombieslft;
int ammolft = ammo - smg.use;
ammo = ammolft;
int healthlft = health - smg.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades
<< " grenades left \nYour health is at " << health << " HP and you still have "
<< zombieslft << " zombies left to kill.\n Hurry soldier!" << endl;
system("PAUSE");
system ("CLS");
goto check;
}
if (weapon == "shotgun");
{
int zombieslft = zombies - shotgun.damage;
zombies = zombieslft;
int ammolft = ammo - shotgun.use;
ammo = ammolft;
int healthlft = health - shotgun.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades <<
" grenades left \nYour health is at " << health << " HP and you still have "
<< zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;
}
if (weapon == "sniper")
{
int zombieslft = zombies - Sniper.damage;
zombies = zombieslft;
int ammolft = ammo - Sniper.use;
ammo = ammolft;
int healthlft = health - Sniper.damage;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades
<< " grenades left \nYour health is at " << health << " HP and you still have "
<< zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;
}
if (weapon == "grenade")
{
int zombieslft = zombies - grenade.messdemup;
zombies = zombieslft;
int nadeslft = nades - 1;
nades = nadeslft;
int healthlft = health - grenade.messdemup;
health = healthlft;
cout << "You have : " << ammo << " shots left and " << nades <<
" grenades left \nYour health is at " << health << " HP and you still have "
<< zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;
}
// everytime I start this game the grenade kills 3 zombies instead of 12
if (weapon == "knife")
{
int zombieslft = zombies - knife.messdemup;
zombies = zombieslft;
int healthlft = health - knife.messdemup;
cout << "You have : " << ammo << " shots left and " << nades <<
" grenades left \nYour health is at " << health << " HP and you still have " <<
zombies << " zombies left to kill.\n Hurry soldier!" << endl;
system ("PAUSE");
system ("CLS");
goto check;
}
}
Line 18: the meh label is never referenced so you don't need it.
Line 39: what is this for? You never use the character r, so you should remove it.
Line 88: you should remove the semicolon after the if, as currently it will always execute the stuff inside the block.
Please copy and paste this code, I did not modify anything except for the formatting.
With the fixes made it kills 6 zombies as you have in your code at the beginning of main - I have no idea why you expected 6 to translate into 12.