Mar 1, 2016 at 12:15am Mar 1, 2016 at 12:15am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#include "stdafx.h"
#include <iostream>
#include "time.h"
int main()
{
srand((unsigned int )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;
}
else if (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!" ;
}
}
else if (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;
}
else if (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!" ;
}
}
}
else if (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.
Last edited on Mar 1, 2016 at 12:16am Mar 1, 2016 at 12:16am UTC
Mar 1, 2016 at 3:39am Mar 1, 2016 at 3:39am UTC
Line 79 if (SerildaHP == 0)
try
if (SerildaHP <= 0)
same thing for line 49
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.