© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
15 replies
CarlJohnson

Need help with a bug

Hi, im currently making one of my exercises and i am stuck on a bug. Im making a bossfight thing based on random numbers if it is a critical damage or not. The bug im stuck is the one on the picture. it seems that the damage goes to 200 but the max damage is 100 when critical and 50 when normal. does anyone see the mistake i made?

my code:
class Program
{
static void Main()
{
int attack = 50;
double critChance = 0.33;
int bossHP = 1000;

Random damage = new();

int attackCalc = attack;
do
{
double chance = damage.NextDouble();
if (chance < critChance)
{
attackCalc *= 2;
}
bossHP -= attackCalc;


if (bossHP < 0)
{
bossHP = 0;
}

Console.WriteLine($"Boss HP: {bossHP}");
Console.WriteLine($"Damage: {attackCalc}");
}
while (bossHP > 0);
Console.WriteLine("Boss defeated");
}
}
Screenshot_2024-09-06_235601.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ help with bug
C#CC# / help
3y ago
✅ Need help with a function
C#CC# / help
13mo ago
need help with a plugin
C#CC# / help
3y ago
❔ need help with a problem
C#CC# / help
4y ago