194k views
5 votes
Write a C# program that converts currencies between British currency of pounds andpence, in which 1 pound contains 100 pence, and U.S. currency in dollars and cents.Assume an exchange rate of 1.6595 U.S. dollars per British pound. Give the user a menuto choose the type of conversion. Allow the user to repeat as often as desired. (See TestYour Understanding questions 39 and 41.)

User ECorke
by
8.5k points

1 Answer

3 votes
Here's program. Add your own rate below, I've added commentary where. Try it:
double amount;
string currency;
Dictionary<string, double> factors = new Dictionary<string, double>(); factors.Add("GBP", 1.1111D);
factors.Add("USD", 1.11111D); // here you can add the rate you need
Console.WriteLine("Please enter the amount of Euro you wish to be converted:");
amount = double.Parse(Console.ReadLine());
Console.WriteLine("");
Console.WriteLine("Please choose the currency you wish to convert to:"); Console.WriteLine("USD");
Console.WriteLine("GBP"); Console.WriteLine("");
currency = Console.ReadLine();
double factor;
if (factors.TryGetValue(currency, out factor))
{
Console.WriteLine("You have entered {0} EUR which converts to {1} {2}", amount, amount * factor, currency);
}
else
{
Console.WriteLine("You did not enter a recognised currency {1}", currency);
}
User Keisha W
by
8.4k points