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

Question #182740

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


1
Expert's answer
2021-04-18T11:22:47-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Q182740
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter the currency value: ");
            double currencyValue = double.Parse(Console.ReadLine());
            Console.Write("Enter the name of the country: ");
            string countryName = Console.ReadLine();
            double equivalentDollars = calculateEquivalent(currencyValue, countryName);
            if (equivalentDollars != -1)
            {
                Console.WriteLine("The equivalent in U.S. dollar = {0} USD", equivalentDollars.ToString());
            }
            else {
                Console.WriteLine("Incorrect country name. Example: \"British Pound\"");
            }
            Console.ReadLine();
        }
        static double calculateEquivalent(double currencyValue, string countryName)
        {


            string[] countryCurrency = { "British Pound", "Canadian Dollar", "Japanese Yen", "German Mark", "Philippines Peso" };
            double[] dollarFactors = { 0.6, 1.3, 140, 1.7, 53 };
            for (int i = 0; i < dollarFactors.Length; i++)
            {
                if (countryName==countryCurrency[i])
                {
                    return  currencyValue / dollarFactors[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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS