Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.NET Modulus/Averaging program

Status
Not open for further replies.

asphyx9

IS-IT--Management
Jul 31, 2003
7
US
I am new to VB.NET and I am trying to write a program that finds the average of all the even numbers between 1 and a user entered number (both inclusive). I am trying to make use of a looping construct, and not a formula. I know that I have may have to use the Modulus function as well as writing a averaging function, but I do not know how to implement it. Any ideas of code examples or what I am trying to do here? Thanks in advance for your time!
 
By using the Modulus function, you will be able to tell if the item is odd or even very easily.

i.e.:

If i mod 2 = 0 then the number is even.
If i mod 2 <> 0 then the number is odd.

Using this, you can loop through your numbers (1 through given number) and add these numbers together into a variable. You will also need to keep a count of the numbers with which you have added, of course, to get the average at the end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top