this is the one that is happening twice/three times when you type the choice once
1 2 3 4 5 6 7 8 9 10 11 12
if (choice == 'st' || choice == 'ST')
{
SheildTackle = (rand() % 25) + 1;
hitpoints = (hitpoints - SheildTackle);
cout << "You hit a " << SheildTackle << endl;
cout << "A Bloodfly has " << hitpoints << "hitpoints left.\n";
hit = (rand() % 20) + 1;
life = (life - hit);
cout << "A Bloodfly his " << hit << endl;
cout << "You have " << life << "hitpoints left.\n";
}
for those of you wondering, i managed to fix it, and it really was a nub move xD for some reason using multiple letters for a choice such as QQ qq oo etc will cause it to pick the choice twice? and 3 letters = picks the choice 3 times? so i made my st choice into t and my usep one into p and it just works now
this is the one that just acts as if its not there
1 2 3 4 5 6 7 8 9 10 11 12
if (choice == 'st' || choice == 'ST')
{
SheildTackle = (rand() % 25) + 1;
hitpoints = (hitpoints - SheildTackle);
cout << "You hit a " << SheildTackle << endl;
cout << "A Bloodfly has " << hitpoints << "hitpoints left.\n";
hit = (rand() % 20) + 1;
life = (life - hit);
cout << "A Bloodfly his " << hit << endl;
cout << "You have " << life << "hitpoints left.\n";
}
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
usingnamespace std;
int main()
{
constint MAX_ITEMS = 5;
string setup[MAX_ITEMS];
int items = 0;
setup[items++] = "Dagger";
setup[items++] = "Sheild";
setup[items++] = "Leather Hide Curiass";
srand(time(0));
int pot = 5;
int slash = rand();
int SheildTackle = rand();
int lunge = rand();
int hit = rand();
char choice;
int hitpoints = 100;
int life = 100;
cout << "\t\@@@ @@@ @@@@@@@ @@@@@@@@ @@@ @@@ @@@@@@@ @@@@@@ @@@@@@@ @@@ @@@ \n";
cout << "\t\@@! !@@ @@! @@@ @@! @@!@!@@@ @!! @@! @@@ @@! @@@ @@! !@@ \n";
cout << "\t\@!@@!@! @!@!!@! @!!!:! @!@@!!@! @!! @!@!@!@! @!@!!@! @!@@!@! \n";
cout << "\t\!!: :!! !!: :!! !!: !!: !!! !!: !!: !!! !!: :!! !!: :!! \n";
cout << "\t\ : ::: : : : : :: :: :: : : : : : : : : : ::: \n\n";
cout << "\t\ @@@@@@ @@@@@@@ @@@@@@@@ @@@ @@@ @@@@@@ \n";
cout << "\t\ @@! @@@ @@! @@@ @@! @@!@!@@@ @@! @@@\n";
cout << "\t\ @!@!@!@! @!@!!@! @!!!:! @!@@!!@! @!@!@!@!\n";
cout << "\t\ !!: !!! !!: :!! !!: !!: !!! !!: !!!\n";
cout << "\t\ : : : : : : : :: ::: :: : : : :\n\n";
cout << "\n\nIn this mini game you will be pitted against various monsters";
cout << " from krentark.\n";
cout << "can you survive?\n";
cout << "You Currently have:\n";
for(int i = 0; i < items; ++i)
cout << setup[i] << endl;
cout << "\nYour first fight is against A Bloodfly.\n";
cout << "When you fight you have to select one of three moves.\n";
cout << "Slash, SheildTackle, Lunge.\n";
cout << "\nA Bloodfly: Bzzzzzzz\n";
char again;
while(again == 'n' || again || 'N')
{
cout << "What would you like to do?\n";
cout << "Slash (s) SheildTackle (st) Lunge (l): ";
cin >> choice;
if (choice == 's'|| choice == 'S')
{
slash = (rand() % 30) + 1;
hitpoints = (hitpoints - slash);
cout << "You hit a " << slash << endl;
cout << "A Bloodfly has " << hitpoints << "hitpoints left.\n";
hit = (rand() % 25) + 1;
life = (life - hit);
cout << "A Bloodfly his " << hit << endl;
cout << "You have " << life << "hitpoints left.\n";
}
if (choice == 'st' || choice == 'ST')
{
SheildTackle = (rand() % 25) + 1;
hitpoints = (hitpoints - SheildTackle);
cout << "You hit a " << SheildTackle << endl;
cout << "A Bloodfly has " << hitpoints << "hitpoints left.\n";
hit = (rand() % 20) + 1;
life = (life - hit);
cout << "A Bloodfly his " << hit << endl;
cout << "You have " << life << "hitpoints left.\n";
}
if (choice == 'l' || choice == 'L')
{
lunge = (rand() % 20) + 1;
hitpoints = (hitpoints - lunge);
cout << "You hit a " << lunge << endl;
cout << "A Bloodfly has " << hitpoints << "hitpoints left.\n";
hit = (rand() % 25) + 1;
life = (life - hit);
cout << "A Bloodfly his " << hit << endl;
cout << "You have " << life << "hitpoints left.\n";
}
if (choice == 'upot')
{
if ( pot > 0 )
{pot = (pot - 1);
life = (life + 20);
cout << "you not have" << pot << "left\n";
cout << "Your health is now" << life << "\n" ;}
elseif (pot = 0)
{cout << "you do not have enough pot\n";}
}
// Declaring Winner
char weapon;
if (hitpoints <= 0)
{
cout << "You defeated A Bloodfly\n";
cout << "When you take a weapon, sometimes it may replace";
cout << " a weapon you already have.\n";
cout << "Would you like a Rapier (r) Iron Shield (i) Potion(p)\n";
cin >> weapon;
// Selecting Weapon
if (weapon == 'r' || weapon == 'R') // Rapier
{
cout << "You've choosen the Rapier.";
cout << "Your inventory is now:\n";
setup[0] = "Rapier";
for (int i = 0; i < items; ++i)
cout << setup[i] << endl;
}
if (weapon == 'i' || weapon == 'I') // Iron Shield
{
cout << "You've choosen an Iron Shield.";
cout << "Your inventory is now:\n";
setup[1] = "Iron Shield";
for (int i = 0; i < items; ++i)
cout << setup[i] << endl;
}
if ( weapon == 'p' || weapon == 'P')
{
cout << "You've choosen a Poiton";
cout << "Your inventory is now:\n";
setup[items++] = "Potion";
for (int i = 0; i < items; ++i)
cout << setup[i] << endl;
}
cout << "Would you like to continue the battle!<Y/N>";
cin >> choice;
if (choice == 'y'|| choice == 'Y')
if (life <= 0)
{
cout << "A Bloodfly has defeated you.";
cout << "You have died";
return 0;
}
}
}
cout << "Thanks for playing.\n";
return 0;
}
}
}
Please note: i know the potion reward part after killing a bloodfly is useless, i havent set that up yet, also i know theres no N option yet, im adding that, the only fixes i need are for the ones i mentioned,
ps i put this in the beginners section because i only started coding yesterday and knowing me its probablly something very small i dont see