9 Replies - 7054 Views - Last Post: 28 May 2008 - 12:15 PM Rate Topic: -----

#1 powellm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 30-March 08

getting the average using input boxes and for next statement

Posted 15 May 2008 - 08:03 PM

so far i have this for my code i need to use input boxes to receive the number of visitors for 5 days also needing to use a for next statement

Const strTitle As String = "Attendance"
Const strPrompt As String = "Enter the Attendance (-1 to finish):"
Const intSentinel As Integer = -1
Dim intVisitors As Integer

This post has been edited by powellm: 16 May 2008 - 12:49 PM

Is This A Good Question/Topic? 0
  • +

Replies To: getting the average using input boxes and for next statement

#2 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: getting the average using input boxes and for next statement

Posted 15 May 2008 - 08:54 PM

Well, assuming you're going to be getting the number of visitors for each individual day, then my suggestion is to create an array to hold the data for each five days, that would make it pretty easy to use a For-Next statement to calculate an average as you could use its counter to check each value of the array.

That's a good hint I think.. doesn't give too much away but points you in a good direction.

This post has been edited by Zhalix: 15 May 2008 - 08:57 PM

Was This Post Helpful? 0
  • +
  • -

#3 powellm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 30-March 08

Re: getting the average using input boxes and for next statement

Posted 16 May 2008 - 01:54 PM

View PostZhalix, on 15 May, 2008 - 08:54 PM, said:

Well, assuming you're going to be getting the number of visitors for each individual day, then my suggestion is to create an array to hold the data for each five days, that would make it pretty easy to use a For-Next statement to calculate an average as you could use its counter to check each value of the array.

That's a good hint I think.. doesn't give too much away but points you in a good direction.


i have not learned about arrays yet can you show me something that is on beginner level
Was This Post Helpful? 0
  • +
  • -

#4 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: getting the average using input boxes and for next statement

Posted 16 May 2008 - 07:07 PM

This is what you need right?

Dim intVisitors As Integer
Dim strVisitors As String

For i = 1 To 5

	strVisitors = InputBox("Enter the attendants for day " & i & ":")
	
	If IsNumeric(strVisitors) = True Then
		If strVisitors > 0 Then
			intVisitors = intVisitors + strVisitors
		End If
	End If

Next i

lblAverageVisitors.Caption = intVisitors / 5


Was This Post Helpful? 0
  • +
  • -

#5 powellm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 30-March 08

Re: getting the average using input boxes and for next statement

Posted 17 May 2008 - 09:10 PM

thanks
Was This Post Helpful? 0
  • +
  • -

#6 powellm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 30-March 08

Re: getting the average using input boxes and for next statement

Posted 27 May 2008 - 03:56 PM

this is my code so far but i cannot seem to get the calculation for the average right
Private Sub cmdStart_Click()
Dim i As Integer
Dim intAverage As Integer
Dim intVisitors As Integer
Dim intSum As Integer
Dim intCounter As Integer
Dim strVisitors As String

intSum = 0
intCounter = 0

For i = 1 To 5

strVisitors = InputBox("Enter the attendants for days Monday through Friday")

If strVisitors <> "" Then
intSum = intSum + i
intCounter = intCounter + 1
End If
Next i

If intCounter > 0 Then intAverage = intSum / intCounter

lblAverageMessage.Caption = "The average attendance for five days is"
lblAverage.Caption = intAverage

End Sub
Was This Post Helpful? 0
  • +
  • -

#7 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: getting the average using input boxes and for next statement

Posted 27 May 2008 - 05:47 PM

In your code..
For i = 1 To 5

strVisitors = InputBox("Enter the attendants for days Monday through Friday")

If strVisitors <> "" Then
intSum = intSum + i
intCounter = intCounter + 1
End If
Next i



Change this line..
intSum = intSum + i


to
intSum = intSum + strVisitors



That should fix it.
Though I don't see why you changed it so much from my code in the first place since mine did the same thing. :blink:

This post has been edited by Zhalix: 27 May 2008 - 05:52 PM

Was This Post Helpful? 0
  • +
  • -

#8 powellm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 30-March 08

Re: getting the average using input boxes and for next statement

Posted 27 May 2008 - 09:10 PM

something is not right because it does not evaluate the math correctly
Was This Post Helpful? 0
  • +
  • -

#9 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: getting the average using input boxes and for next statement

Posted 28 May 2008 - 12:33 AM

Even after you changed what I said?

Can you describe the problem in more detail?

Only thing I can think of that might not be working correctly is that you're putting the outcome of the equation intSum / intCounter into an integer variable. Those don't hold decimal points. Just change the data type from integer to one that supports decimals.

This post has been edited by Zhalix: 28 May 2008 - 12:41 AM

Was This Post Helpful? 0
  • +
  • -

#10 powellm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 30-March 08

Re: getting the average using input boxes and for next statement

Posted 28 May 2008 - 12:15 PM

thank you for helping me the problem was with the variables
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1