# visual basic

posted by .

Im trying to get this program to average three number having a problem the sample nmubers im using are 6 6 2 average supposed to be 4.6667 but im just geting .6667 I think it has something to do with my s=value(i) not sure what i need to do now can anybody help?

Dim no As Integer = 3
Dim value() As Integer
ReDim value(0 To no - 1)
Dim s As Integer = 0
For i As Integer = 0 To no - 1
s = value(i)
Next
Dim a As Double = s / no
Console.WriteLine(" value is " & a)

• visual basic -

You just have a minor typo,
s = value(i)
s += value(i)

Everything falls in place.

• visual basic -

Are the numbers to be averaged always integers?
If not, you have some corrections to do.

• visual basic -

thanks yes the numbers are always to be averaged as integers.

• visual basic -

You're welcome anytime, I love programming!

• visual basic -

Ok got one more i need help on the program below im supposed to sort the usernames and passwords in alphabetical order by username. Then display the sorted resort. I was able to sort username alphabetically but im not sure how to get the passwords to match up with the usernames.

Dim n As Integer = 5
Dim user(0 To n - 1) As String
Dim password(0 To n - 1) As String

For i As Integer = 0 To n - 1
Console.Write(" Enter user name: ")

Next

'Sorting the entered user names

'using bubble sort

For i As Integer = 0 To 4
For j As Integer = 0 To n - i - 2

If (user(j) > user(j + 1)) Then

swap(user(j), user(j + 1))

End If
Next
Next

For i As Integer = 0 To n - 1

Console.WriteLine(user(i))

Next

End Sub

Sub swap(ByRef str1 As String, ByRef str2 As String)

Dim temp As String

temp = str1

str1 = str2

str2 = temp

• visual basic -

I didn't verify your code, but I see the general way to do it. Suppose you have

now, after the swap above, you have

which is wrong, but you can fix it easily by swapping the passwords along with the names, like:

If (user(j) > user(j + 1)) Then
swap(user(j), user(j + 1))
End If

and now user and password will stay together.

• visual basic -

Exactly!
With Jim's proposed corrections, you'd be on your way.

Also, if the value of n is a constant, you could replace Dim n... by
Const N as integer=5
This will help the compiler check for code that tries to modify N.

• visual basic -

thanks i really appericate the help! Im starting to like programming more myself!

• visual basic -

Good to hear! Till next time.

## Similar Questions

1. ### COMPUTER PROGRAMMING

Could you please help me write a program using basic or visual basic that would prevent spam/unsolicited e-mails computers. You have to be kidding. If not, you need a reality check. Do you actually think anyone will do that for you …
2. ### programming

I am supposed to modify this program so it begins by asking the user for the number of values. The program then uses a loop to read the specified number of values and then display their average. program is below that i worked on in …
3. ### visual basic

in visual basic, notes in a program which explain what the program is doing are called?
4. ### Programming

I need your help to write a program using visual basic 2010 for the following:- write a program that calculates the average of up to 50 numbers input by the user and stored in an arrey. The program should use a class named Statistics …
5. ### Programming

Here is the question that I need help to write the code for the following program in Visual Basic 2010. I am trying to write the code but it has a run time error. If your could helps me to write the code it would be greatly appreciated. …
6. ### Word Problem

A UPS employee, Davis, packs and labels three types of packages: basic packages, business packages, and oversized packages. Business packages take a priority over basic packages, and oversized packages because those customers paid …
7. ### college algebra

I think this is an exponential equation. I can not figure out how to put the equation into the TI-84 to get the approximate form 3/5 ln(5x-1)+1 =1.4 subtract 1 from sides and divide by 3/5 lh(5x-1)=0.6667 Put in logarithm form e^0.6667=5x-1 …
8. ### math

if cotx+tanx=a and secx-cosx=b then prove that (a^2b)^0.6667 -(ab^2)^0.6667=1
9. ### VISUAL BASIC PROGRAMMING

3. WRITE A VISUAL BASIC PROGRAM TO CALCULATE THE SIMPLE INTEREST ON A LOAN AMONUT OF 50000 GHANA CEDIS AT AN INTEREST RATE OF 30% FOR A NUMBER OF YEARS WHICH WILL BE SPECIFIED BY THE USER.
10. ### visual basic

Write a visual basic program to calculate total pay of employee who get an additional pay of 10% to their basic salary if they worked for more than 10years for the company

More Similar Questions