I am making a code where the user is asked, "How many marks are there?" and then they put in the number of marks they mentioned. After that, it prints out the maximum mark and the minimum mark.
int MarkNumber;
Console.Write("How many marks are there?: ");
MarkNumber = Convert.ToInt32(Console.ReadLine());
for (int SchoolM = 0; SchoolM < MarkNumber; SchoolM++)
{
Console.Write("Input a Mark: ");
Console.ReadLine();
}
I am not the best at coding so I have no direction of how to find the max and min in a loop. I got up to the part where they are able to input the marks, but I am unsure of how to find the max and the min. I have looked up how to do the max and min, but it usually shows up for finding the max and min in arrays and that is not what I desire to do.
int currentMark; int min = 0; int max = 0;
. Inside the loop:currentMark = Convert.ToInt32(Console.ReadLine()); if (currentMark > max) max = currentMark; else if (currentMark < min) min = currentMark;
. Alternatively, you could add the marks to a list and calculate the min and max afterward. – 41686d6564int.TryParse()
overConvert.ToInt32()
. – 41686d6564