#include "stdafx.h"
#include <iostream>
#include "time.h"
int main()
{
srand((unsignedint)time(NULL));
int SerildaHP;
int LunaHP;
SerildaHP = 10;
LunaHP = 10;
std::cout << "Welcome Back!";
std::cout << "To start game, click 1 , to exit, click 2!";
int startOrEnd;
std::cin >> startOrEnd;
if (startOrEnd == 1)
{
std::cout << "Pick Serilda click 1 or Luna click 2!";
int serildaOrLuna;
std::cin >> serildaOrLuna;
if (serildaOrLuna == 1){
while (LunaHP != 0)
{
std::cout << "THE BATTLE HAS BEGUN!Click 1 or 2 to switch skills!";
int Skill;
std::cin >> Skill;
if (Skill == 1)
{
int a = rand() % 4;
std::cout << "You dealt" << a << "% of Luna's HP.";
LunaHP = LunaHP - a;
}
elseif (Skill == 2)
{
int b = rand() % 6;
std::cout << "You dealt" << b << "% of Luna's HP.";
LunaHP = LunaHP - b;
}
}
if (LunaHP == 0){
std::cout << "You've won!";
}
}
elseif (serildaOrLuna == 2){
std::cout << "The Battle has begun!";
while (SerildaHP != 0)
{
std::cout << "Click 1 or 2 to switch skills!";
int Skill;
std::cin >> Skill;
if (Skill == 1)
{
int negativeser = rand() % 4;
std::cout << "You dealt" << negativeser << "% of Serilda's HP.";
SerildaHP = SerildaHP - negativeser;
}
elseif (Skill == 2)
{
int negativesera = rand() % 6;
std::cout << "You dealt" << negativesera << "% of Serilda's HP.";
SerildaHP = SerildaHP - negativesera;
}
}
if (SerildaHP == 0){
std::cout << "Luna Wins!";
}
}
}
elseif (startOrEnd == 2){
std::cout << "We're sorry to see you go :(";
}
}
Sometimes it comes to an end, but sometimes it just NEVER stops, it takes forever to win.It seems like there's some sort of bug, but it only happens sometimes.Help.
With the equals test you're doing, the HP has to be exactly 0, so the random numbers have to come out perfectly to zero. If you change it to <= it doesn't have to be exact, it can be less than zero.