Im having trouble working out making a converter for mutliple currencys using multiple subs. I keep receiving an error saying that number is a friend , and therefore cannot be used in the jap conversion . can anyone help ? thank you in advance
Option Explicit On
'Option Strict On
Imports System
Module Yahtzed
Sub CANtoUSD()
Dim Number , USDConversion as Decimal
Number = Console.Readline
USDConversion =( Number * 1.0141)
Console.Writeline(USDConversion)
End Sub
Sub CANtoJAP()
Dim Number, JAPConversion as Decimal
Number = Console.Readline
JAPConversion =( Number * 79.9392)
Console.Writeline(JAPConversion)
End Sub
Sub Main()
Console.Writeline("Enter the CAN amount: ")
CANtoUSD()
CANtoJAP()
End Sub
End Module
Not a direct answer, but this requires more space than would work in a comment.
You have a fundamental design error in your code. You really want to structure it more like this:
You don’t want to mix responsibilities for you methods. The input/output should be strictly separated from the code that manipulates the data. If nothing else, this makes it easier to test that your specific conversion methods work exactly like they are supposed to, and could not be the source of your bug.
Later on, you’ll learn how to also ahave a single method that accepts a key value for both source and destination types, and does a table lookup to convert any currency to any other by knowing the conversion factor to a common currency.