Robson » Little Red Book » Currency Conversion #2

Chapter 2 - Question 5

Write programs to convert from each of the following currencies to pounds sterling.

  1. United States Dollars
  2. French Francs
  3. Dutch Guilders
  4. Austrian Schillings
  5. Danish Krona

Input is to be a number representing a quantity in pounds, sterling; output is to be equivalent amount and the currency unit involved.

Solution 1

VB2005 console application:

Module Module1
 
   Sub Main()
 
       ' currenct exchange rates, see menu below for what they relate to
       Dim dblRates() As Double = {0.53409, 0.103309, 0.307509, 0.0492474, 0.0908731}
 
       ' show the user a basic menu
       Console.WriteLine("Welcome to the currency onverter!" & vbNewLine & _
         "Which currency do you have?" & vbNewLine & _
         "1. United States Dollars" & vbNewLine & _
         "2. French Franc" & vbNewLine & _
         "3. Dutch Guilders" & vbNewLine & _
         "4. Austrian Schillings" & vbNewLine & _
         "5. Danish Krona")
 
       ' they type the number that relates to their currency
       Dim intCurrency As Integer = Val(Console.ReadLine())
 
       ' ask how many the user has
       Console.WriteLine("How many of those do you have?")
 
       ' they type the amount they have
       Dim dblAmount As Double = Val(Console.ReadLine())
 
       ' show how much that is in gbp
       Console.WriteLine("That's equal to " & _
         dblRates(intCurrency - 1) * dblAmount & _
         " Pounds Sterling." & vbNewLine & _
         "Press any key to exit...")
 
       ' terminate after key press
       Console.ReadKey()
 
   End Sub
 
End Module

Log

© 2004-17 robson | cc unless stated