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;
namespace Q179088
{
class Program
{
static void Main(string[] args){
string[] COUNTRIES = new string[] { "Canada", "United States", "U.S.S.R.", "Italy", "Philippines" };
string[] CAPITALS = new string[] { "Ottawa", "Washington D.C.", "Moscow", "Rome", "Manila" };
//ccept the name of the country as input value
Console.Write("Enter the name of the country: ");
string countryCountry = Console.ReadLine();
bool isFound = false;
for (int i = 0; i < COUNTRIES.Length; i++) {
if (COUNTRIES[i].CompareTo(countryCountry) == 0) {
//display the corresponding capital
Console.WriteLine("The capital of the country {0} is {1}", countryCountry,CAPITALS[i]);
isFound = true;
break;
}
}
if (!isFound) {
Console.WriteLine("\nThe capital is not found for this country.\n");
}
Console.ReadLine();
}
}
}
Comments
Leave a comment