Results 1 to 11 of 11

Thread: Coding Help

Threaded View

  1. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If you mean EVERY even number between 1 and 100 then here is an example:
    VB Code:
    1. 'loop thru 1(2 since 1 is odd) to 100 skipping every other one (step 2)
    2.         Dim sum As Integer
    3.         Dim count As Integer
    4.         For nmbr As Integer = 2 To 100 Step 2
    5.             'increment the count
    6.             count += 1
    7.             'add to the sum
    8.             sum += nmbr
    9.         Next
    10.         'get average
    11.         Dim result As Single = sum / count
    12.         'build a string to show results
    13.         Dim sb As New System.Text.StringBuilder
    14.         sb.Append(String.Format("There a {0} even numbers between 1 and 100.{1}", count, ControlChars.NewLine))
    15.         sb.Append(String.Format("The sum of these numbers is {0}.{1}", sum, ControlChars.NewLine))
    16.         sb.Append(String.Format("The average of these numbers is {0}.", result))
    17.         'show results string
    18.         MsgBox(sb.ToString)
    If you mean a selection of numbers between 1 and 100 then build off of dynamic_sysop's post.
    Last edited by Edneeis; Sep 26th, 2003 at 04:16 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width