Reference no: EM132238552
An application named DailyTemps that continuously prompts a user for a series of daily high temperatures until the user enters a sentinel value of 999. Valid temperatures range from -20 through 130 Fahrenheit. When the user enters a valid temperature, add it to a total; when the user enters an invalid temperature, display the error message:
Valid temperatures range from -20 to 130. Please reenter temperature.
Before the program ends, display the number of temperatures entered and the average temperature.
This is my code below. It's not giving me what I need. I need average and number of Array. What am i doing wrong?
using System;
using static System.Console;
class DailyTemps
{
static void Main()
{
int temp = 0;
int total = 0;
int [] tempNum = new int [temp];
while (temp != 999)
{
WriteLine("Please enter a number valid temperature range from -20 to 130");
temp = Convert.ToInt32(ReadLine());
if ((temp >= -20) && (temp <= 130))
{
total = total + temp;
}
else if (temp != 999)
{
WriteLine("Valid temperature range is from -20 to 130. Please reenter temperature. ");
}
for (int i = 0; i < tempNum.Length; ++i)
{
total = total/tempNum.Length;
}
}
WriteLine("The total temperature is {0}, {1}", tempNum.Length, total);
ReadLine();
}
}