lundi 2 mars 2015

Newbie C++ issue involving while loops and OR statements


I am having an issue learning C++ basics involving the while loop. When I run my program it works well, until I get to the while loop involving an OR (||) statement. while (totalhumanHP > 0 || totalskeletonHP > 0) should continue until one hits zero then stop correct? It is only keeping tabs on totalhumanHP and letting skeletonHP dip into the negatives without stopping. I am not sure how or why the OR statement isnt functioning in the while loop.



#include <iostream>
#include <string>
#include <random>
#include <ctime>

using namespace std;

int main()
{
cout << "-----SKELETMANS V HOOMINS-----\n";
int skeletonHP = 90;
int humanHP = 100;
int skeletonDMG = 1;
int humanDMG = 1;
int totalskeleton = 1; //Inputted Skele's
int totalhuman = 1; //Inputted hoomins
int totalskeletonHP; //Overall Skele HP
int totalhumanHP; //Overall Hoomin HP
string battlecry;
string battlecryenter;

default_random_engine generator(time(0));
uniform_int_distribution<int> skeletonrng(1, 22);
uniform_int_distribution<int> humanrng(1, 20);

cout << "How Many Skeletmans: ";
cin >> totalskeleton;
cout << "How Many Houmints: ";
cin >> totalhuman;

totalskeletonHP = totalskeleton * skeletonHP;
totalhumanHP = totalhuman * humanHP;

cout << "Overall Skeleton HP= " << totalskeletonHP << endl;
cout << "Overall Hoomint HP= " << totalhumanHP << endl;
cout << endl;
cout << "What is your battlecry?\n (You can use this to start the battle)";
cout << endl;
cin >> battlecry;
battlecry == battlecryenter;

cout << "Use Your Battlecry To Start The Fight!!!\n\n\n\n\n";
cout << "BattleCry: ";
cin >> battlecryenter;

if (battlecryenter == battlecry)
{
cout << "THE FIGHT HAS COMMENCED!!!\n\n\n\n";
}
else{
cout << "You 4got alreedy? UR DOMB MING\n\n";
cout << "ACTUAL BattleCry: ";
cin >> battlecryenter;

if (battlecryenter == battlecry)
{
cout << "THE FIGHT HAS COMMENCED!!!\n\n\n\n";
}
}

int endskeleton = 0;
int endhuman = 0;

while (totalhumanHP > 0 || totalskeleton > 0)
{
skeletonDMG = skeletonrng(generator);
humanDMG = humanrng(generator);
totalhumanHP = totalhumanHP - skeletonDMG;
totalskeletonHP = totalskeletonHP - humanDMG;

cout << "END SKELETON: " << totalskeletonHP << endl;
cout << "END HOOMING: " << totalhumanHP << endl;

}
cout << "Skeleton Ramaining Health: " << totalskeletonHP << endl;
cout << "Human Remaining Health: " << totalhumanHP << endl;
system("PAUSE");
return 0;
}



Aucun commentaire:

Enregistrer un commentaire