The following method print this:
Minimum Temperature is 16
Maximum Temperature is 27
The Average Temperature is 22
Now I want in addition to temperatures I also have the days in which the temperatures was maximum and minimum like:
Minimum Temperature is 16 on Day 6
Maximum Temperature is 27 on Day 8
The Average Temperature is 22
Here is the method which inserts Day and Temperature as dictionary parameters into an array and pass them to a method which determines the min,max, average.
the min and max are int values of the dictionary ,my question is that how we can determine the related string day based on these values?
// if user select January , the January() execute:
protected void Button1_Click(object sender, EventArgs e)
{
// assigning Days and Temperatures to Dictionary and making array dictionary
Dictionary<string, int>[] temperatures = new Dictionary<string, int>[10];
temperatures[0] = new Dictionary<string, int>();
temperatures[1] = new Dictionary<string, int>();
temperatures[2] = new Dictionary<string, int>();
temperatures[3] = new Dictionary<string, int>();
temperatures[4] = new Dictionary<string, int>();
temperatures[5] = new Dictionary<string, int>();
temperatures[6] = new Dictionary<string, int>();
temperatures[7] = new Dictionary<string, int>();
temperatures[8] = new Dictionary<string, int>();
temperatures[9] = new Dictionary<string, int>();
temperatures[0].Add("Day1", 22);
temperatures[1].Add("Day2", 23);
temperatures[2].Add("Day3", 25);
temperatures[3].Add("Day4", 26);
temperatures[4].Add("Day5", 18);
temperatures[5].Add("Day6", 16);
temperatures[6].Add("Day7", 17);
temperatures[7].Add("Day8", 27);
temperatures[8].Add("Day9", 23);
temperatures[9].Add("Day10", 24);
if (DropDownList1.SelectedValue.ToString() == "January")
{
January(temperatures);
}
//the metthod which calculate min ,max and ..
private void January(Dictionary<string, int>[] temperatures)
{
int Minimumtemperture = 40;
int Maximumtemperture = 0;
int total = 0;
int averageTemperatures = 0;
// this foreach goes through array
foreach (var temperture in temperatures)
{
// this foreach goes throuh dictionary
foreach (var degree in temperture)
{
//assigning value of each dictionary to the monthTemp
int MonthTemps = degree.Value;
if (MonthTemps < Minimumtemperture)
{
Minimumtemperture = MonthTemps;
}
if (MonthTemps>Maximumtemperture)
{
Maximumtemperture = MonthTemps;
}
total = total + MonthTemps;
}
int totaltemperature = temperatures.Length;
averageTemperatures = (total / totaltemperature);
}
// printing the result
Label1.Text = string.Format("Minimum Temperature is {0}<br/> Maximum Temperature is{1}<br/> The Average Temperature is{2}<br/>", Minimumtemperture, Maximumtemperture, averageTemperatures);
}