Answer to Question #180652 in C# for Patrick Ian Kyle Mabunay

Question #180652

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


1
Expert's answer
2021-04-14T13:42:35-0400
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");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS