while (userInput < 800)
{
if (userInput >0 && userInput <= 200)
{
cOne++;
sumLengthOne = sumLengthOne + userInput;
userInput = int.Parse(Console.ReadLine());
if (userInput > largestValue)
{
largestValue = userInput;
}
if (userInput < smallestValue)
{
smallestValue = userInput;
}
}
else if (userInput >200 && userInput <= 400)
{
cTwo++;
sumLengthTwo = sumLengthTwo + userInput;
userInput = int.Parse(Console.ReadLine());
if (userInput > largestValue)
{
largestValue = userInput;
}
if (userInput < smallestValue)
{
smallestValue = userInput;
}
}
else if (userInput >400 && userInput <= 600)
{
cThree++;
sumLengthThree = sumLengthThree + userInput;
userInput = int.Parse(Console.ReadLine());
if (userInput > largestValue)
{
largestValue = userInput;
}
if (userInput < smallestValue)
{
smallestValue = userInput;
}
}
else if (userInput >600 && userInput <= 800)
{
cFour++;
sumLengthFour = sumLengthFour + userInput;
userInput = int.Parse(Console.ReadLine());
if (userInput > largestValue)
{
largestValue = userInput;
}
if (userInput < smallestValue)
{
smallestValue = userInput;
}
}
Console.WriteLine("The Largest Bacteria Is: " + largestValue); Console.WriteLine("The Smallest Bacteria Is: " + smallestValue);
The output is :
The Largest Bacteria Is: 900
The Smallest Bacteria Is: 67
The largest bacteria should not be able to be over 800 as it is nested in the while loop at the beginning?
Aucun commentaire:
Enregistrer un commentaire