C
Join ServerC#
help
✅ Why am I getting this exception?
Sshawski2/2/2023
class algo{
public static void Main(string [] args){
addList.numbers();
int numofMax = 0;
int max = addList.birthdayCandles.Max();
for (int i = 0; i > addList.birthdayCandles.Count; i ++){
if (addList.birthdayCandles[i] == max){
numofMax++;
}
}
Console.WriteLine("/m" + numofMax);
}
}
public class addList
{
public static List<int> birthdayCandles = new List<int>();
public static List<int> numbers()
{
Random rng = new Random();
int rngAmount = 0;
Console.WriteLine("Please insert a number: ");
while (!int.TryParse(Console.ReadLine(), out rngAmount))
{
Console.WriteLine("Please insert a number: ");
}
for (int i = 0; i > rngAmount; i++)
{
int num = rng.Next(1, 10);
birthdayCandles.Add(num);
}
for (int i = 0; i > birthdayCandles.Count; i++){
Console.Write(birthdayCandles[i] + " ");
}
return birthdayCandles;
}
}

Vvdvman12/2/2023
i > rngAmount
in your for loop is guaranteed to be false immediately, because 0
can't be larger than any of the random numbers you are generatingVvdvman12/2/2023
As such, the for loop never runs
Vvdvman12/2/2023
You have the same issue in your other 2 for loops
Vvdvman12/2/2023
You almost certainly wanted
<
instead of >
Sshawski2/2/2023
ahhh
Sshawski2/2/2023
wait
Sshawski2/2/2023
god i always do that
Sshawski2/2/2023
alright gimme one sec
Sshawski2/2/2023
yeah it works now.
Sshawski2/2/2023
well thanks for pointing that out, dont know how i missed that