Question

VisualBasic programm You were asked to write a program that identifies positive and negative numbers which...

VisualBasic programm You were asked to write a program that identifies positive and negative numbers which the user enters. Then calculate the average of negative and positive numbers separately. You need to follow the steps below; a. Ask the user to enter the number of data which she/he likes to enter. b. Declare necessary variables as ARRAYS. c. Use a For Next loop to get the data from the user d. Use a decision structure to decide whether the number is positive (>=0) or negative (<0) e. Take the average of negative numbers f. Take the average of positive numbers g. Print the following to worksheet cells i. All the numbers entered by the user ii. Average of negative numbers iii. Average of positive numbers

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

Private Sub CommandButton1_Click()
Dim ARRAYS() As Integer
Dim num, i, countPos, countNeg, totalP, totalN As Integer
Dim avgNeg, avgPos As Double
countNeg = 0
countPos = 0
totalP = 0
totalN = 0

num = CInt(InputBox("How many numbers do you want in the array: "))
ReDim ARRAYS(num)

For i = 0 To num - 1
ARRAYS(i) = CInt(InputBox("Enter a number: "))
Next i

For i = 0 To num - 1
Cells(i + 1, 1) = ARRAYS(i)
Next i


For i = 0 To num - 1
If (ARRAYS(i) >= 0) Then
totalP = totalP + ARRAYS(i)
countPos = countPos + 1
End If
If (ARRAYS(i) < 0) Then
totalN = totalN + ARRAYS(i)
countNeg = countNeg + 1
End If
Next i

avgPos = totalP / countPos

If (countNeg = 0) Then
MsgBox ("There are no negative numbers!!")
Else
avgNeg = totalN / countNeg
End If

Cells(num + 2, 1) = "Average of Positive numbers: " & avgPos
Cells(num + 4, 1) = "Average of Negative numbers: " & avgNeg


End Sub

Output:

Microsoft Visual Basic for Applications - Bookl running - [ Userform (Code)] 0 File Edit View Insert Format Debug Run Tools A

Add a comment
Know the answer?
Add Answer to:
VisualBasic programm You were asked to write a program that identifies positive and negative numbers which...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that calculates the average of a stream of non-negative numbers. The user can...

    Write a program that calculates the average of a stream of non-negative numbers. The user can enter as many non-negative numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, zero counts as a number that goes into the average. Of course, the negative number should not be part of the average (and, for this program, the average of 0 numbers is 0). You must use a method to read...

  • 1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The...

    1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The program should use the for loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50. If the user enters a zero or negative number, a message should be given and the program should not continue (see Sample Run...

  • (Count positive and negative numbers and compute the average of numbers) Write a program that reads...

    (Count positive and negative numbers and compute the average of numbers) Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number. If you entire input is 0, display 'No numbers are entered except 0.' *So I think my code is looping because the...

  • Write a program using M.I.P.S that asks user “how many positive number that is devisable by...

    Write a program using M.I.P.S that asks user “how many positive number that is devisable by 6 you want to add?” .Then your loopcounter would be the user input. If the user enters a positive number between 1 and 100 that is devisable by 6, you increment your loop counter and add it to the sum.. You need to decide if the positive number entered by the user is divisible by 6 or not. Your program should print an error...

  • Write a C – program that calls a user-defined function from within main() that determines the...

    Write a C – program that calls a user-defined function from within main() that determines the minimum value from three positive numbers received from the user. Your function should be called minimum.  You must use a loop to receive the numbers. If the user enters a negative number, you must ask the user to re-enter the number. The function should also print out the positive numbers and the smallest number.

  • need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that...

    need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...

  • 1. Write a program to add positive numbers. Ask the user to enter numbers greater than...

    1. Write a program to add positive numbers. Ask the user to enter numbers greater than zero. If a 0, is entered stop requesting numbers and display the total. If a number is entered that is less than 0, display the message ‘Number must be greater than 0’, then ask for another number to be entered. Repeat until a number greater than 0 or 0 is entered. use math lab so I can copy the answers

  • C++ Programming Help Please! NOTE: Please READ All Steps very carefully. DO #10! (10 is based...

    C++ Programming Help Please! NOTE: Please READ All Steps very carefully. DO #10! (10 is based off of 9). Program Info:   #9. Write a program that reads in ten whole numbers and that outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the ten numbers just once...

  • In this exercise, write a complete Java program that reads integer numbers from the user until...

    In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...

  • write a program code that asks the user how many numbers they wish to find the...

    write a program code that asks the user how many numbers they wish to find the statistics of and then asks the user to enter those numbers. The program must then calculate and display the average variance and standard deviation of the numbers entered by the user. the program code must -ask three user how many numbers they wish to find the statistics of -ask the user to enter those numbers and store them in an array - use a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT