Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help, below I have pasted my code VB code. When it is ran I'm supposed to get the output in the picture. However when

Please help, below I have pasted my code VB code.

When it is ran I'm supposed to get the output in the picture. However when I run my code I'm getting "0.00" instead of "3.00". Also if I dont enter any information into the textbox I get an error saying "VB conversion from string to type integer is not valid". image text in transcribed .

Public Class frmCIS115 Private Sub btnClick_Click(sender As Object, e As EventArgs) Handles btnClick.Click Dim number, value, counter, avg As Integer Dim total As Double

DataOk() GetInput(value) ProcessNumber(value, total, counter) Average(total, counter, avg) DisplayAverage(avg) End Sub 'Function to make sure the data is numeric and not less than 3 and not greater than 10 Function DataOk() As Boolean If IsNumeric(txtNum.Text) = False Then MessageBox.Show("You must enter a number") txtNum.Text = "" txtNum.Focus() Return False ElseIf CInt(txtNum.Text) 10 Then MessageBox.Show("Number cannot be greater 10 or less than 3!") txtNum.Text = "" txtNum.Focus() Return False Else Return True End If End Function 'Subprocedure to get input Sub GetInput(ByRef value As Integer) value = CInt(txtNum.Text) End Sub 'Subprocedure to display what goes in the listbox Sub ProcessNumber(ByVal value As Integer, ByRef total As Integer, ByRef counter As Integer) lstOutput.Items.Add("") lstOutput.Items.Add("The numbers you entered were: ") For i As Integer = 1 To value Dim number As Integer = InputBox("Please enter numbers") lstOutput.Items.Add(number) If number Mod 2 = 0 Then number += total counter += 1 End If Next End Sub 'Function for calculating Function Average(ByVal total As Integer, ByVal counter As Integer, ByRef avg As Double) As Integer avg = total / counter Return avg End Function 'Function displaying average Function DisplayAverage(ByVal avg As Double) As String lstOutput.Items.Add("") lstOutput.Items.Add("The average of the even numbers is " & avg.ToString("n2")) End Function End Class

CIS 115 - Review Enter a Number between 3 and 10: 5 Click Here The numbers you entered were 7 The average of the even numbers is 3.00

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions