-
Apr 14th, 2014, 03:34 PM
#1
Thread Starter
Junior Member
Standard deviation
Hi everyone= I can't get my code for the standard deviation to work. I have to create a program for curving grades with a median and standard deviation, and then assign letter grades to the scores.
my code for the median is :
Option Explicit
Private Sub cmdShow_Click()
Dim score(1 To 20) As Integer
Dim stanDeviation As Integer
Dim index As Integer
Call FillArray(score())
picExam.Cls
picExams.Print "There were 20 "exams"
picExams.Print "Mean:"; Sum(score()) / 20
picExams.Print "Std. Deviation: "; Round(Sqr(stDev), 5)
Private Function Sum(s() As Integer) As Integer
Dim total As Integer, index As Integer
'This will add the scores for the mean
total = 0
For index = 1 To 20
total = total + s(index)
Next index
Sum = total
End Function
Private Function Deviation(s() As Integer) As Integer
Dim index As Integer
Dim stDev As Integer
'Calculates the deviation
stDev = 0
For index = 1 To 20
stDev= stDev+ ((s(index) - 70.65) ^ 2 / 20)
Next index
End Function
Could anyone Tell me what is wrong with equation code? The code for the median works just fine.
-
Apr 14th, 2014, 03:44 PM
#2
Re: Standard deviation
You're not assigning a result to the function Deviation. You need 'deviation = stDev' before the End Function. Also you need 'Round(Sqr(deviation), 5)' in the print statement. I suspect that the deviation should be a Real type rather than Integer.
-
Apr 14th, 2014, 04:11 PM
#3
Thread Starter
Junior Member
Re: Standard deviation
I added the deviation = stDev, but I still get a 0.
-
Apr 14th, 2014, 04:48 PM
#4
Re: Standard deviation
Have you changed the Integers to Real?
-
Apr 14th, 2014, 04:50 PM
#5
Thread Starter
Junior Member
Re: Standard deviation
We only use Integer, Single and String in the class
-
Apr 14th, 2014, 06:40 PM
#6
Re: Standard deviation
Code:
picExams.Print "Std. Deviation: "; Round(Sqr(stDev), 5)
I think you meant to call the deviation function there btu instead you are using the var from inside the function would have a value of 0
Actually it should be giving you an error as the var is not defined in the current scope. Perhaps it is defined global somewhere else?
-
Apr 15th, 2014, 01:30 AM
#7
Re: Standard deviation
Originally Posted by DaniTapi
We only use Integer, Single and String in the class
Sorry, I meant Single.
-
Apr 15th, 2014, 08:09 AM
#8
Re: Standard deviation
This post is NOT to solve your problem, BUT, I noted that you set your variables to zero (stDev=0, and Total=0) immediately after Declaring them. Those statements are not required as the Declaration will default those values to 0.
-
Apr 15th, 2014, 08:17 AM
#9
Re: Standard deviation
PS---You can also drop the "Call" callword.
-
Apr 15th, 2014, 01:38 PM
#10
Thread Starter
Junior Member
Re: Standard deviation
The Call FillArray(score()) Holds the scores, so I can not drop it. I have already turned my assignment in as is, I will post the solution to my question before I mark this resolved. Just waiting for the instructor to post it.
-
Apr 15th, 2014, 01:48 PM
#11
Re: Standard deviation
No, I meant you can drop the CALLWORD, "CALL".
This works: FillArray(score))
No need for the word "Call"....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|