Write a program using string functions that will accept the name of the country as input value and will display the corresponding capital. Here is the list of the countries and their capitals.
COUNTRY CAPITAL
Canada Ottawa
United States Washington D.C.
U.S.S.R. Moscow
Italy Rome
Philippines Manila
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
private static string GetCapicalCity(string country)
{
if (country.Equals("Canada", StringComparison.InvariantCultureIgnoreCase))
return "Ottawa";
if (country.Equals("United States", StringComparison.InvariantCultureIgnoreCase))
return "Washington D.C.";
if (country.Equals("U.S.S.R.", StringComparison.InvariantCultureIgnoreCase))
return "Moscow";
if (country.Equals("Italy", StringComparison.InvariantCultureIgnoreCase))
return "Rome";
if (country.Equals("Philippines", StringComparison.InvariantCultureIgnoreCase))
return "Manila";
return "";
}
static void Main(string[] args)
{
Console.Write("Enter country: ");
string capital = GetCapicalCity(Console.ReadLine().Trim());
if (capital != "")
Console.WriteLine("Capital city: " + capital);
else
Console.WriteLine("Not Found");
}
}
}
Comments
Leave a comment