I have an array with limit of 5 values. The code as writen allows the user to enter a 6th number before averaging the first five number. I want to stop the user from being able to enter that 6th number. thanks for any help. Code below:
Code:
using System;
public class SumNumbersArray
{
public static void Main()
{
int [] arrayA=new int[5];
int number, count=0;
double sum=0.0, average;
String strNumber;
Console.Out.WriteLine("Enter a number (999 to quit): ");
strNumber=Console.ReadLine();
number=Convert.ToInt32(strNumber);
while(count<5 && number != 999)
{
arrayA[count]=number;
count++;
//loop thru asking for the next number until the while condition returns false
Console.Out.WriteLine("Enter a number (999 to quit): ");
strNumber=Console.ReadLine();
number=Convert.ToInt32(strNumber);
}
for(int i=0; i<count; i++)
sum = sum + arrayA[i];
average=sum/count;
Console.Out.WriteLine("the average of your numbers is: " + average);
}
}
Comment