Having a problem. Wrote program originally as VB Console using Sub procedures, had to change it to Function. It worked as sub procedures, but now as function it won't calculate correctly, I actually have two that are doing the same thing because of the procedure switch! Grr! Any suggestions?

Sub Main()

    'Declarations
    Dim dblMidTerm As Double = 0 
    Dim dblFinal As Double = 0
    Dim dblAvgTotal As Double = 0 

    'Calculate Average 
    dblAvgTotal  CalculateTotalAverage(dblMidTerm, dblFinal) 

    ‘Display Average
    displayTotalAverage(dblAvgTotal)
    terminateProgram()

End Sub 

Private Sub getExamGrades(ByRef dblMidTerm As Double, ByVal dblFinal As Double) 

    Console.Write("What was your midterm exam numerical grade? ") 
    dblMidTerm = CDbl(Console.ReadLine()) 
    Console.Write("What was your final exam numerical grade? ") 
    dblFinal = CDbl(Console.ReadLíne())

End Sub 

Private Function CalculateTotalAverage(ByVal dblMidTerm AS Double, ByVal dblFinal As Double) As Double 

    Dim dblAvgTotal As Double = 0 
    dblAvgTotal = CDbl((dblMidTerm + dblFinal) / 2) 
    Return dblAvgTotal 

End Function 

Private Sub displayTotalAverage(ByVal dblAvgTotal As Double) 

    Console.WriteLine("The average of your midterm and Final grades is " & dblAvgTotal) 
    Console.WriteLine() 

End Sub 

Private Sub terminateProgram() 

    Console.WriteLine("Press the enter key to terminate program. ") 
    Console. Read() 

End Sub 

End Module

Edited 2 Years Ago by Reverend Jim: fixed formatting

In the sample you posted above you aren't calling getExamGrades at all so dblMidTerm and dblFinal never change from zero. You then pass 2 zeros into CalculateTotalAverage and get nothing back.
You are calling getExamGrades in the PDF though.

I copied that from Google Drive and had trouble with the transfer, I thought I had fixed everything. The PDF is exactly what I wrote, and it is dividing by 2 twice, and I can't seem to rectify the problem. I have added parantheses and taken them out, in case of order of operations problem, and nothing worked.

How about changing

dblAvgTotal  CalculateTotalAverage(dblMidTerm, dblFinal) 

to

dblAvgTotal = CalculateTotalAverage(dblMidTerm, dblFinal) 

Thanks Reverend Jim, But that was an error I missed from the google drive transfer, if you look at the PDF it is there.

OK. Now that I'm awake (I really shouldn't answer questions at 4:00 am), you never call GetExamGrades so your values are always 0.

Edited 2 Years Ago by Reverend Jim

Can't be that awake, you didn't read my first post ;)
Brandy1, I really can't see what is causing the problem. I have looked at the PDF and gone through it but there isn't any cause for the doubling that I can see. Can you confirm the PDF is the actual code you are using? Maybe re-post the actual code so we stop getting confused.

Crazy me, in the first private sub, i didn't call the final grade by reference, only by value! Woo hoo!

This question has already been answered. Start a new discussion instead.