Question #179091

Write a program that will accept the currency value and the name of the country and will display the equivalent in U.S. dollar, based on the given list:



COUNTRY CURRENCY U.S. DOLLAR EQUIVALENT

British Pound 0.6 U.S. dollar

Canadian Dollar 1.3 U.S. dollar

Japanese Yen 140 U.S. dollar

German Mark 1.7 U.S. dollar

Philippines Peso 53 U.S. dollar


Expert's answer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Q179091
{
    class Program
    {
        static void Main(string[] args)
        {


            //Read the currency value
            Console.Write("Enter the currency value: ");
            double currencyValue = double.Parse(Console.ReadLine());
            //Read the name of the country
            Console.Write("Enter the name of the country: ");
            string nameCountry = Console.ReadLine();
            //display the equivalent in U.S. dollar
            double dollarEquivalent = getDollarEquivalent(nameCountry);
            if (dollarEquivalent != -1)
            {
                double dollars = dollarEquivalent * currencyValue;
                Console.WriteLine("The equivalent in U.S. dollar: " + dollars.ToString("C"));
            }
            else
            {
                Console.WriteLine("Enter correct the country currency. Example: \"Canadian Dollar\"");
            }
            Console.ReadLine();
        }
        /// <summary>
        /// This function allows to get dollar equivalent according to the country currency
        /// </summary>
        /// <param name="nameCountry"></param>
        /// <returns></returns>
        static double getDollarEquivalent(string nameCountry)
        {
            string[] countryCurrency = { "British Pound", "Canadian Dollar", "Japanese Yen", "German Mark", "Philippines Peso" };
            double[] dollarEquivalent = { 0.6, 1.3, 140, 1.7, 53 };
            for (int i = 0; i < dollarEquivalent.Length; i++)
            {
                if (nameCountry.CompareTo(countryCurrency[i]) == 0)
                {
                    return dollarEquivalent[i];
                }
            }
            return -1;
        }
    }
}

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!

LATEST TUTORIALS
APPROVED BY CLIENTS