using System.Collections.Generic;
using System.Net.Http.Headers;
public List<weather> weather
public string description
public static void Main(string[] args)
for (int i = 0; i < 5; i++)
Console.Write("Enter location: ");
string location1 = Console.ReadLine();
location = location + ":" + location1;
if (location.StartsWith(":"))
location = location.Remove(0, 1);
if (location.EndsWith(":"))
location = location.Remove(location.Length, 1);
string[] strPlace = location.Split(new char[]{':'});
for (int i = 0; i < strPlace.Length; i++)
using (var client = new HttpClient())
client.BaseAddress = new Uri("http://api.openweathermap.org/data/2.5/forecast");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string key = "eb831772830e52d36b4d086599ec9aac";
HttpResponseMessage response = client.GetAsync("?q=" + strPlace[i] + "&AppID=" + key).Result;
if (response.StatusCode == HttpStatusCode.OK)
var details = response.Content.ReadAsStringAsync().Result;
var _openweather = JsonConvert.DeserializeObject<openweather>(details);
Console.WriteLine("+++++++++++++++++++++++++---------------------------+++++++++++++++++++++++++++");
if(string.IsNullOrEmpty(_openweather.city.name))
Console.WriteLine("City : " );
Console.WriteLine("City : " + _openweather.city.name);
for (int j = 0; j <= _openweather.list.Count(); j++)
Console.WriteLine("Date : " + "{0:MM/dd/yyyy}", _openweather.list[j].dt_txt);
if(string.IsNullOrEmpty(_openweather.list[j].main.temp))
Console.WriteLine("Avg Temp(F) : Not Available Now");
Console.WriteLine("Avg Temp(F) : " + Math.Round(((Convert.ToDouble(_openweather.list[j].main.temp) - 273.15) * 1.8) + 32).ToString("F"));
_str = _openweather.list[j].dt_txt.ToString("MM/dd/yyyy");
else if (_str != _openweather.list[j].dt_txt.ToString("MM/dd/yyyy"))
Console.WriteLine("Date : " + "{0:MM/dd/yyyy}", _openweather.list[j].dt_txt);
Console.WriteLine("Avg Temp(F) : " + Math.Round(((Convert.ToDouble(_openweather.list[j].main.temp) - 273.15) * 1.8) + 32).ToString("F"));
_str = _openweather.list[j].dt_txt.ToString("MM/dd/yyyy");
Console.WriteLine("+++++++++++++++++++++++++---------------------------+++++++++++++++++++++++++++");
Console.WriteLine(ex.Message);