There is a lot of code to this program now and I have narrowed my problem down to one of my classes. It compiles fine but when I run the program and go through a few options its good. After I got a class set up I tried to see if I could get some output from them but it crashes the console.
Here is the class I am using:
One of these members is what I think is crashing the program.Code:class Weapons { public: Weapons(); string getWeaponValue(); //Legendary, Epic, unique, rare, magical, normal string getWeaponType(); //Sword, mace, staff string getWeaponName(); //Name the weapon int getWeaponStats(); // damage, +mods and durability int getMagicStats(); int getWeaponLevel(); // level of the weapon void whoCanDrop(); //check to see which mobs can drop it private: string WeaponName; string WeaponType; string WeaponValue; int WeaponStats; int WeaponDamage; int WeaponDurability; int WeaponLevel; char CanIDropIt; };
Pardon all the weird placement of some of the text, I had to edit this to get it to fit to the page so it wouldn't be so wide. Its not how I have it in my program. And here is the int main()Code:string Weapons::getWeaponValue() { int x; srand(time(0)); x = 1 + rand() % 8; switch (x) { case 1: WeaponValue ="Normal"; case 2: WeaponValue = "Magical"; case 3: WeaponValue = "Rare"; case 4: WeaponValue = "Unique"; case 5: WeaponValue = "Epic"; case 6: WeaponValue = "Legendary"; default: WeaponValue = "Normal"; cout <<WeaponValue; } } string Weapons::getWeaponType() { int x; srand(time(0)); x = 1 + rand() % 10; switch (x){ case 1: WeaponType = "Sword"; case 2: WeaponType = "Dagger"; case 3: WeaponType = "Mace"; case 4: WeaponType = "Staff"; case 5: WeaponType = "Wand"; case 6: WeaponType = "Axe"; case 7: WeaponType = "Club"; default: WeaponType = "Exotic"; } //cout <<WeaponType; } string Weapons::getWeaponName() { int x; srand(time(0)); if (WeaponType == "Sword" && WeaponValue == "Normal" && WeaponLevel <= 10) { x = 1 + rand() % 12; switch (x){ case 1: WeaponName = "RustedSword"; case 2: WeaponName = "DullSword"; case 3: WeaponName = "BrokenSword"; case 4: WeaponName = "UnforgedSword"; case 5: WeaponName = "BluntSword"; case 6: WeaponName = "WeakSword"; case 7: WeaponName = "Tiny"; case 8: WeaponName = "Sharp Knife"; default: WeaponName = "WoodenSword"; } } if (WeaponType == "Mace" && WeaponValue == "Normal" && WeaponLevel <= 10) { x = 1 + rand() % 12; switch (x){ case 1: WeaponName = "RustedMace"; case 2: WeaponName = "DullMace"; case 3: WeaponName = "BrokenMace"; case 4: WeaponName = "UnforgedMace"; case 5: WeaponName = "BluntMace"; case 6: WeaponName = "WeakMace"; case 7: WeaponName = "Chunky"; case 8: WeaponName = "SharpMace"; default: WeaponName = "WoodenMace"; } } if (WeaponType == "Axe" && WeaponValue == "Normal" && WeaponLevel <= 10) { x = 1 + rand() % 12; switch (x){ case 1: WeaponName = "RustedAxe"; case 2: WeaponName = "DullAxe"; case 3: WeaponName = "BrokenAxe"; case 4: WeaponName = "UnforgedAxe"; case 5: WeaponName = "BluntAxe"; case 6: WeaponName = "WeakAxe"; case 7: WeaponName = "Pointy"; case 8: WeaponName = "SharpAxe"; default: WeaponName = "Hatchet"; } } if (WeaponType == "Club" && WeaponValue == "Normal" && WeaponLevel <= 10) { x = 1 + rand() % 12; switch (x){ case 1: WeaponName = "SplinteredClub"; case 2: WeaponName = "FlatClub"; case 3: WeaponName = "BrokenClub"; case 4: WeaponName = "UnforgedClub"; case 5: WeaponName = "BluntClub"; case 6: WeaponName = "WeakClub"; case 7: WeaponName = "Skinny"; case 8: WeaponName = "ThickClub"; default: WeaponName = "WoodenClub"; } } if (WeaponType == "Dagger" && WeaponValue == "Normal" && WeaponLevel <= 10) { x = 1 + rand() % 12; switch (x){ case 1: WeaponName = "RustedDagger"; case 2: WeaponName = "DullDagger"; case 3: WeaponName = "BrokenDagger"; case 4: WeaponName = "UnforgedDagger"; case 5: WeaponName = "BluntDagger"; case 6: WeaponName = "WeakDagger"; case 7: WeaponName = "Poinert"; case 8: WeaponName = "SharpDagger"; default: WeaponName = "WoodenDagger"; } } if (WeaponType == "Staff" && WeaponValue == "Normal" && WeaponLevel <= 10) { x = 1 + rand() % 12; switch (x){ case 1: WeaponName = "SplinteredStaff"; case 2: WeaponName = "CrackedStaff"; case 3: WeaponName = "BrokenStaff"; case 4: WeaponName = "UnforgedStaff"; case 5: WeaponName = "BluntStaff"; case 6: WeaponName = "WeakStaff"; case 7: WeaponName = "LongStaff"; case 8: WeaponName = "HardStaff"; default: WeaponName = "WoodenStaff"; } } if (WeaponType == "Wand" && WeaponValue == "Normal" && WeaponLevel <= 10) { x = 1 + rand() % 12; switch (x){ case 1: WeaponName = "RustedWand"; case 2: WeaponName = "BurntWand"; case 3: WeaponName = "BrokenWand"; case 4: WeaponName = "UnforgedWand"; case 5: WeaponName = "WornWand"; case 6: WeaponName = "WeakWand"; case 7: WeaponName = "Sparky"; case 8: WeaponName = "BrightWand"; default: WeaponName = "WoodenWand"; } cout <<WeaponName; } if (WeaponType == "Sword" || WeaponType == "Axe" || WeaponType == "Mace" || WeaponType == "Dagger" || WeaponType == "Wand" || WeaponType == "Club" || WeaponType == "Staff" && WeaponValue =="Magical" && WeaponLevel >=3) { x = 1 + (rand() % 10) - Clvl; switch (x){ case 1: WeaponName = "Of the Bear"; case 2: WeaponName = "Of the Wolf"; case 3: WeaponName = "Of the Bird"; default: WeaponName = "Mended Weapon"; } cout <<WeaponName; } if (WeaponType == "Sword" || WeaponType == "Axe" || WeaponType == "Mace" || WeaponType == "Dagger" || WeaponType == "Wand" || WeaponType == "Club" || WeaponType == "Staff" && WeaponValue =="Magical" && WeaponLevel >=5) { x = 1 + (rand() % 10) - Clvl; switch (x){ case 1: WeaponName = "Of the Bear"; case 2: WeaponName = "Of the Wolf"; case 3: WeaponName = "Of the Bird"; case 4: WeaponName = "Of the Monkey"; case 5: WeaponName = "Of the Scorpid"; default: WeaponName = "Glowing Sword"; } cout <<WeaponName; } if (WeaponType == "Sword" || WeaponType == "Axe" || WeaponType == "Mace" || WeaponType == "Dagger" || WeaponType == "Wand" || WeaponType == "Club" || WeaponType == "Staff" && WeaponValue =="Magical" && WeaponLevel >=10) { x = 1 + (rand() % 23) - Clvl; switch (x){ case 1: WeaponName = "Of the Bear"; case 2: WeaponName = "Of the Wolf"; case 3: WeaponName = "Of the Bird"; case 4: WeaponName = "Of the Monkey"; case 5: WeaponName = "Of the Scorpid"; case 6: WeaponName = "Of the Wise"; case 7: WeaponName = "Of the Mystics"; case 8: WeaponName = "Of the Devine"; case 9: WeaponName = "Of the Earth"; case 10: WeaponName = "Of the Brute"; case 11: //might WeaponName = "Of Might"; case 12://wisdom WeaponName = "Of Wisdom"; case 13://gods WeaponName = "Of the Gods"; default: WeaponName = "Glowing Weapon"; } cout <<WeaponName; } } int Weapons::getWeaponStats() { if (WeaponType == "Sword" || WeaponType == "Mace" || WeaponType == "Dagger" || WeaponType == "Axe" || WeaponType == "Club" || WeaponType == "Staff" || WeaponType == "Wand" && WeaponValue == "Normal" && Clvl <= 3) { WeaponStats = 0; WeaponDamage = (Clvl * WeaponLevel) + Str; WeaponDurability = 1 + rand() % 20; } if (WeaponType == "Sword" && WeaponValue == "Normal" && Clvl <= 5) { WeaponStats = 0; WeaponDamage = (Clvl * WeaponLevel) + Str; WeaponDurability = 1 + rand() % 30; } if (WeaponType == "Sword" && WeaponValue == "Normal" && Clvl <= 10) { WeaponStats = 0; WeaponDamage = (Clvl * WeaponLevel) + Str; WeaponDurability = 1 + rand() % 50; } int getMagicStats(string WeaponType, string WeaponValue, string WeaponName); WeaponDamage = 1 + (rand() % 10) - Clvl; WeaponDurability = 1 + rand() % 20; } int Weapons::getMagicStats() { int x; //random variable to create random numbers int y; //random variable to decide stat int z; //random variable to decide number of a single stat srand(time(0)); if (WeaponValue == "Magical") { WeaponDamage = (Clvl * WeaponLevel) + Str; WeaponDurability = Clvl * WeaponLevel; } if (WeaponValue == "Magical") { if (WeaponName == "Of the Bear") // +str(lots), +hp(lots) and small amount of +agi(small) { int x; x = 1 + rand() % 8; //Number of stats switch (x){ case 1: WeaponMod1 = Clvl * (1 + rand() % WeaponLevel); case 2: WeaponMod1 = Clvl * (1 + rand() % WeaponLevel); WeaponMod2 = Clvl * 3 * (1 + rand() % WeaponLevel); case 3: WeaponMod1 = Clvl * (1 + rand() % WeaponLevel); WeaponMod2 = Clvl * 4 * (1 + rand() % WeaponLevel); WeaponMod4 = Clvl + (1 + rand() % WeaponLevel); default: WeaponMod1 = Clvl * (1 + rand() % WeaponLevel); } } if (WeaponName == "Of the Wolf") // +str(small), +hp(small) and +agi(lots) { int x; x = 1 + rand() % 8; //Number of stats switch (x){ case 1: if (Clvl == 1) WeaponMod1 = Clvl * (1 + rand() % WeaponLevel); if (Clvl >= 2) WeaponMod1 = (Clvl / 2) * (1 + rand() % WeaponLevel); case 2: if (Clvl == 1) WeaponMod1 = Clvl * (1 + rand() % WeaponLevel); if (Clvl >= 2) WeaponMod1 = (Clvl / 2) * (1 + rand() % WeaponLevel); WeaponMod2 = Clvl * 2 * (1 + rand() % WeaponLevel); case 3: if (Clvl == 1) WeaponMod1 = Clvl * (1 + rand() % WeaponLevel); if (Clvl >= 2) WeaponMod1 = (Clvl / 2) * (1 + rand() % WeaponLevel); WeaponMod2 = (Clvl * 2) * (1 + rand() % WeaponLevel); WeaponMod4 = (Clvl * 3) + (1 + rand() % WeaponLevel); default: WeaponMod4 = (Clvl * 3) + (1 + rand() % WeaponLevel); } } if (WeaponName == "Of the Bird") // +hp(very small) +mp(small) +agi(lots) { int x; x = 1 + rand() % 8; //Number of stats switch (x){ case 1: WeaponMod2 = Clvl * (1 + rand() % WeaponLevel); case 2: WeaponMod2 = Clvl * (1 + rand() % WeaponLevel); WeaponMod3 = Clvl * (1 + rand() % WeaponLevel); case 3: WeaponMod2 = Clvl * (1 + rand() % WeaponLevel); WeaponMod3 = (Clvl * 2) * (1 + rand() % WeaponLevel); WeaponMod4 = (Clvl * 3) + (1 + rand() % WeaponLevel); default: WeaponMod4 = (Clvl * 2) + (1 + rand() % WeaponLevel); } } if (WeaponName == "Of the Monkey") // +hp's(very small) +agi(very much) { int x; x = 1 + rand() % 8; //Number of stats switch (x){ case 1: WeaponMod2 = Clvl * (1 + rand() % WeaponLevel); case 2: WeaponMod2 = Clvl * (1 + rand() % WeaponLevel); WeaponMod4 = (Clvl * 6) + (1 + rand() % WeaponLevel); default: WeaponMod4 = (Clvl * 4) + (1 + rand() % WeaponLevel); } } if (WeaponName == "Of the Scorpid") // +hp(very small) +agi(small) +armor(lots) { int x; x = 1 + rand() % 8; //Number of stats switch (x){ case 1: WeaponMod2 = Clvl * (1 + rand() % WeaponLevel); case 2: WeaponMod2 = Clvl * (1 + rand() % WeaponLevel); WeaponMod4 = (Clvl * 2) + (1 + rand() % WeaponLevel); case 3: WeaponMod2 = Clvl * (1 + rand() % WeaponLevel); WeaponMod4 = (Clvl * 2) + (1 + rand() % WeaponLevel); WeaponMod5 = (Clvl * 5) * (1 + rand() % WeaponLevel); default: WeaponMod5 = (Clvl * 5) + (1 + rand() % WeaponLevel); } } if (WeaponName == "Of the Wise") // +hp(very small) +agi(small) +armor(lots) { int x; x = 1 + rand() % 8; //Number of stats switch (x){ case 1: WeaponMod3 = (Clvl * 10) * (1 + rand() % WeaponLevel); default: WeaponMod3 = (Clvl * 5) * (1 + rand() % WeaponLevel); } } if (WeaponName == "Of the Mystics") // +hp's(lots) +mp's(small) +agi(small) { int x; x = 1 + rand() % 8; //Number of stats switch (x){ case 1: WeaponMod2 = (Clvl * 3) * (1 + rand() % WeaponLevel); case 2: WeaponMod2 = (Clvl * 4) * (1 + rand() % WeaponLevel); WeaponMod3 = (Clvl * 3) * (1 + rand() % WeaponLevel); case 3: WeaponMod2 = (Clvl * 4) * (1 + rand() % WeaponLevel); WeaponMod3 = (Clvl * 3) * (1 + rand() % WeaponLevel); WeaponMod4 = (Clvl * 2) + (1 + rand() % WeaponLevel); default: WeaponMod2 = (Clvl * 4) * (1 + rand() % WeaponLevel); WeaponMod3 = (Clvl * 3) * (1 + rand() % WeaponLevel); } } if (WeaponName == "Of the Devine") // +all stats(small) { int x; x = 1 + rand() % 8; //Number of stats switch (x){ case 1: WeaponMod1 = Clvl * (1 + rand() % WeaponLevel); WeaponMod2 = (Clvl * 2) * (1 + rand() % WeaponLevel); WeaponMod3 = (Clvl * 2) * (1 + rand() % WeaponLevel); WeaponMod4 = (Clvl * 3) + (1 + rand() % WeaponLevel); default: if (Clvl == 1) WeaponMod1 = Clvl * (1 + rand() % WeaponLevel); if (Clvl >= 2) WeaponMod1 = (Clvl / 2) * (1 + rand() % WeaponLevel); WeaponMod2 = Clvl * (1 + rand() % WeaponLevel); WeaponMod3 = Clvl * (1 + rand() % WeaponLevel); WeaponMod4 = (Clvl * 2) + (1 + rand() % WeaponLevel); } } if (WeaponName == "Of the Earth") // +hp +armor(lots) { int x; x = 1 + rand() % 8; //Number of stats switch (x){ case 1: WeaponMod2 = (Clvl * 3) * (1 + rand() % WeaponLevel); case 2: WeaponMod2 = (Clvl * 3) * (1 + rand() % WeaponLevel); WeaponMod5 = (Clvl * 10) + (1 + rand() % WeaponLevel); default: WeaponMod5 = (Clvl * 5) + (1 + rand() % WeaponLevel); } } if (WeaponName == "Of the Brute") // +hp +armor(lots) { int x; x = 1 + rand() % 8; //Number of stats switch (x){ case 1: WeaponMod6 = (Clvl * 5) * (1 + rand() % WeaponLevel); case 2: WeaponMod6 = (Clvl * 3) * (1 + rand() % WeaponLevel); WeaponMod5 = (Clvl * 5) + (1 + rand() % WeaponLevel); default: WeaponMod6 = (Clvl * 7) * (1 + rand() % WeaponLevel); } } if (WeaponName == "Of Might") // 1str 2hp's 6damage { int x; x = 1 + rand() % 8; //Number of stats switch (x){ case 1: WeaponMod1 = (Clvl * 2) + (1 + rand() % WeaponLevel); case 2: WeaponMod1 = (Clvl * 2) + (1 + rand() % WeaponLevel); WeaponMod6 = (Clvl * 3) * (1 + rand() % WeaponLevel); default: WeaponMod6 = (Clvl * 7) * (1 + rand() % WeaponLevel); } } if (WeaponName == "Of Wisdom") // hp mp { int x; x = 1 + rand() % 8; //Number of stats switch (x){ case 1: WeaponMod2 = (Clvl * 8) + (1 + rand() % WeaponLevel); case 2: WeaponMod2 = (Clvl * 5) + (1 + rand() % WeaponLevel); WeaponMod3 = (Clvl * 10) + (1 + rand() % WeaponLevel); default: WeaponMod2 = (Clvl * 3) + (1 + rand() % WeaponLevel); } } if (WeaponName == "Of the Gods") // hp mp { int x; x = 1 + rand() % 8; //Number of stats switch (x){ case 1: WeaponMod1 = (Clvl * 2) + (1 + rand() % WeaponLevel); WeaponMod2 = (Clvl * 8) + (1 + rand() % WeaponLevel); WeaponMod3 = (Clvl * 10) + (1 + rand() % WeaponLevel); WeaponMod4 = (Clvl * 4) + (1 + rand() % WeaponLevel); WeaponMod5 = (Clvl * 5) + (1 + rand() % WeaponLevel); WeaponMod6 = (Clvl * 7) * (1 + rand() % WeaponLevel); case 2: WeaponMod1 = (Clvl * 3) + (1 + rand() % WeaponLevel); WeaponMod2 = (Clvl * 9) + (1 + rand() % WeaponLevel); WeaponMod3 = (Clvl * 11) + (1 + rand() % WeaponLevel); WeaponMod4 = (Clvl * 6) + (1 + rand() % WeaponLevel); WeaponMod5 = (Clvl * 7) + (1 + rand() % WeaponLevel); WeaponMod6 = (Clvl * 8) * (1 + rand() % WeaponLevel); default: WeaponMod1 = (Clvl * 2) + (1 + rand() % WeaponLevel); WeaponMod2 = (Clvl * 5) + (1 + rand() % WeaponLevel); WeaponMod3 = (Clvl * 5) + (1 + rand() % WeaponLevel); WeaponMod4 = (Clvl * 4) + (1 + rand() % WeaponLevel); WeaponMod5 = (Clvl * 5) + (1 + rand() % WeaponLevel); WeaponMod6 = (Clvl * 5) * (1 + rand() % WeaponLevel); } } } }Weapons WepLoot;
Code:int main() { int x; string blah; srand(time(0)); StartGame(); system ("cls"); cout <<"Welcome " <<YourName <<" to the Age of Spire!" <<endl; cout <<endl; cout <<"Do you wish to view the history and backstory?(Y or N)" <<endl; getline(cin, blah, '\n'); if (blah == "y" || blah == "Y") cout <<"Story here." <<endl; else cout <<"Play then." <<endl; WepLoot.getWeaponValue(); WepLoot.getWeaponType(); WepLoot.getWeaponName(); AnyKey(); }



LinkBack URL
About LinkBacks



.
I used to be an adventurer like you... then I took an arrow to the knee.