VB conversion program commenting..

joxley1990

Golden Master
Messages
7,846
COULD NOT POST THIS IN COMPUTER PROGRAMMING SECTION, MODS CAN MOVE.


Does anyone know what to comment on this coding for a conversion program?

Code:
' simple program to convert certain variables  

Module conversionprgram
    ' Main method begins execution of VB conversion program
    Sub Main()
        Console.BackgroundColor = ConsoleColor.Black
        Console.ForegroundColor = ConsoleColor.Red


        'declare variables 

        Dim menuoption As Integer = 0
        Dim continueLooping As Char = "y"
        Dim numberforconversion As Integer
        Dim conversionresult As Integer

        Do
            Console.WriteLine("*********************************")
            Console.WriteLine("<Welcome to the conversion program>")
            Console.WriteLine("<Made by  James Oxley>")
            Console.WriteLine("*********************************")
            Console.WriteLine("")
            ' press 1 to convert kilograms to pounds
            Console.WriteLine("To convert Kilograms to Pounds Press 1 ")
            Console.WriteLine("(1kg = 2.205lbs)")
            Console.WriteLine("---------------------------------------")
            Console.WriteLine("")
            ' press 2 to convert pounds to kilograms
            Console.WriteLine("To convert Pounds to Kilograms press 2 ")
            Console.WriteLine("(1lb = 0.454kg)")
            Console.WriteLine("---------------------------------------")
            Console.WriteLine("")
            ' press 3 to convert centimetres to inches
            Console.WriteLine("To convert Centimetres to Inches press 3 ")
            Console.WriteLine("(1cm = 0.394ins)")
            Console.WriteLine("-----------------------------------------")
            Console.WriteLine("")
            ' press 4 to convert inches to centimetres 
            Console.WriteLine("To convert Inches to Centimetres press 4 ")
            Console.WriteLine("(1inch = 2.54cm)")
            Console.WriteLine("-----------------------------------------")
            Console.WriteLine("")
            ' press 5 to convert kilometres to miles
            Console.WriteLine("To convert Kilometres to Miles press 5 ")
            Console.WriteLine("(1km = 0.621miles)")
            Console.WriteLine("---------------------------------------")
            Console.WriteLine("")
            ' press 6 to convert miles to kilometres
            Console.WriteLine("To convert Miles to Kilometres press 6 ")
            Console.WriteLine("1mile to 1.609km)")
            Console.WriteLine("---------------------------------------")
            Console.WriteLine("")
            ' press 7 to convert litres to pints
            Console.WriteLine("To convert Litres to Pint press 7 ")
            Console.WriteLine("(1ltr to 1.758pt)")
            Console.WriteLine("----------------------------------")
            Console.WriteLine("")
            ' press 8 to convert pint to litres
            Console.WriteLine("To convert Pint to Litres press 8 ")
            Console.WriteLine("(1pt to 0.568ltr)")
            Console.WriteLine("----------------------------------")
            Console.WriteLine("")
            ' press 9 to convert fahrenheit to celsius
            Console.WriteLine("To convert Fahrenheit to Celsius press 9 ")
            Console.WriteLine("((f-32)/9)*5")
            Console.WriteLine("------------------------------------------")
            Console.WriteLine("")
            ' press 10 to convert celsius to fahrenheit
            Console.WriteLine("To convert Celsius to Fahrenheit press 10 ")
            Console.WriteLine("((c*9)/5)+32")
            Console.WriteLine("------------------------------------------")
            Console.WriteLine("")
            ' exit after "0" is pressed
            Console.WriteLine("((To exit without making a conversion, press 0))")





            menuoption = Convert.ToInt32(Console.ReadLine())





            If menuoption = 1 Then
                Console.WriteLine("Kilograms to Pounds. Please Enter amount you would like to convert")
                numberforconversion = Convert.ToInt32(Console.ReadLine())
                conversionresult = numberforconversion * 2.205
                Console.WriteLine("conversionresult: {0} Pounds (lbs)", conversionresult)
                Console.WriteLine("Press any key to repeat menu")
                Console.WriteLine("----------------------------")
                Console.ReadKey(True)


            ElseIf menuoption = 2 Then
                Console.WriteLine("Pounds to Kilgrams. Please Enter amount you would like to convert")
                numberforconversion = Convert.ToInt32(Console.ReadLine())
                conversionresult = numberforconversion * 0.454
                Console.WriteLine("conversionresult: {0} Kilograms (kg)", conversionresult)
                Console.WriteLine("")
                Console.WriteLine("")
                Console.WriteLine("Press any key to repeat menu")
                Console.WriteLine("----------------------------")
                Console.ReadKey(True)

            ElseIf menuoption = 3 Then
                Console.WriteLine("Inches. Please Enter amount you would like to convert")
                numberforconversion = Convert.ToInt32(Console.ReadLine())
                conversionresult = numberforconversion * 0.394
                Console.WriteLine("conversionresult: {0} Inches", conversionresult)
                Console.WriteLine("")
                Console.WriteLine("Press any key to repeat menu")
                Console.WriteLine("----------------------------")
                Console.ReadKey(True)

            ElseIf menuoption = 4 Then
                Console.WriteLine("Inches to Centimetres. Please Enter amount you would like to convert")
                numberforconversion = Convert.ToInt32(Console.ReadLine())
                conversionresult = numberforconversion * 2.54
                Console.WriteLine("conversionresult: {0} Centimetres (cm)", conversionresult)
                Console.WriteLine("")
                Console.WriteLine("Press any key to repeat menu")
                Console.WriteLine("----------------------------")
                Console.ReadKey(True)

            ElseIf menuoption = 5 Then
                Console.WriteLine("Kilometres to Miles. Please Enter amount you would like to convert")
                numberforconversion = Convert.ToInt32(Console.ReadLine())
                conversionresult = numberforconversion * 0.621
                Console.WriteLine("conversionresult: {0} Miles", conversionresult)
                Console.WriteLine("")
                Console.WriteLine("Press any key to repeat menu")
                Console.WriteLine("----------------------------")
                Console.ReadKey(True)

            ElseIf menuoption = 6 Then
                Console.WriteLine("Miles to Kilometres. Please Enter amount you would like to convert")
                numberforconversion = Convert.ToInt32(Console.ReadLine())
                conversionresult = numberforconversion * 1.609
                Console.WriteLine("conversionresult: {0} Kilometres (km)", conversionresult)
                Console.WriteLine("")
                Console.WriteLine("Press any key to repeat menu")
                Console.WriteLine("----------------------------")
                Console.ReadKey(True)

            ElseIf menuoption = 7 Then
                Console.WriteLine("Litres to Pint. Please Enter amount you would like to convert")
                numberforconversion = Convert.ToInt32(Console.ReadLine())
                conversionresult = numberforconversion * 1.758
                Console.WriteLine("conversionresult: {0} Pints", conversionresult)
                Console.WriteLine("")
                Console.WriteLine("Press any key to repeat menu")
                Console.WriteLine("----------------------------")
                Console.ReadKey(True)

            ElseIf menuoption = 8 Then
                Console.WriteLine("Pint to Litres. Please Enter amount you would like to convert")
                numberforconversion = Convert.ToInt32(Console.ReadLine())
                conversionresult = numberforconversion * 0.568
                Console.WriteLine("conversionresult: {0} Litres (ltr)", conversionresult)
                Console.WriteLine("")
                Console.WriteLine("Press any key to repeat menu")
                Console.WriteLine("----------------------------")
                Console.ReadKey(True)

            ElseIf menuoption = 9 Then
                Console.WriteLine("Fahrenheit to Celsius. Please Enter amount you would like to convert")
                numberforconversion = Convert.ToInt32(Console.ReadLine())
                conversionresult = ((numberforconversion - 32) / 9) * 5
                Console.WriteLine("conversionresult: {0} Celsius (°C)", conversionresult)
                Console.WriteLine("")
                Console.WriteLine("")
                Console.WriteLine("Press any key to repeat menu")
                Console.WriteLine("----------------------------")
                Console.ReadKey(True)
 
Code:
ElseIf menuoption = 10 Then
                Console.WriteLine("Celsius to Fahrenheit. Please Enter amount you would like to convert")
                numberforconversion = Convert.ToInt32(Console.ReadLine())
                conversionresult = ((numberforconversion * 9) / 5) + 32
                Console.WriteLine("conversionresult: {0} Fahrenheit (°F)", conversionresult)
                Console.WriteLine("")
                Console.WriteLine("Press any key to repeat menu")
                Console.WriteLine("----------------------------")
                Console.ReadKey(True)


            End If
            ' loop if user requests to
        Loop While menuoption <> 0

    End Sub

End Module

I've got everything commented before the ElseIf options, but I don't know what to comment for the ElseIf coding. My teacher sent me this email, but I don't understand..

My Teacher :) said:
For the If/Elseif comment blocks you need to explain what the condition that is being checked for true/false is and then within those blocks comment the code that does the actual conversion etc.
 
for the first part, I think he wants you to tell him what the different options mean and how they are checked. Such as explaining what the 1,2,3.... and however many you have are. The other part he just wants you to tell what the code is doing during the conversion.
 
for the first part, I think he wants you to tell him what the different options mean and how they are checked. Such as explaining what the 1,2,3.... and however many you have are. The other part he just wants you to tell what the code is doing during the conversion.

No offense, but did you just post that answer based on the email from my teacher, or do you do VB programming, because it just looks like you have changed the wording of the email..
 
I am a software developer, yes. I guess I don't understand what you don't get about commenting. He's trying to teach you to write out important things so that when you get a job writing software, you can write a piece of code and if something goes wrong with it a year later and your not there to fix it, the person assigned to fix it can understand how it works and what it does. Take a step back and look at it from the view of someone who's never seen it, would you understand everything going on from the comments you've written.
Ex: For your if/else statement you should have something explaining what would make it true and what would make it false, exactly as your teacher asked.
For the 2nd part what I would do it at the start of each block write some comments that explain what conversion is being done, how it's done, and the formula being used.
Hopefully that helps, I don't really feel like going through your whole program and telling you line by line what to write as that would somewhat defeat the purpose of what your teacher is trying to teach you. You seem like a smart guy and I'm sure you'll figure it out, just make sure you explain yourself.
 
^ If you don't know the answer then don't post.

two question marks don't help.
 
Back
Top Bottom