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

Question #179088

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-07T07:58:44-0400
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();
        }
    }
}

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