I am currently working on a Visual Basics program to work out the Maximum, Minimum and Mean of the numbers inputted. I currently have it working with up to 50 numbers but I cannot get the Mean to work.
The other problem I have is that I want to be able to enter an infinite amount of numbers and type "END" or "-999" into the console to stop entering the numbers. At the moment you are asked how many numbers you want to enter at the start.
Here is the code:
Imports System.Console
Imports System.Threading
Module Module1
Sub Main()
BackgroundColor = ConsoleColor.White
ForegroundColor = ConsoleColor.Black
Clear()
Dim Max As Integer
Dim Min As Integer
Dim Mean As Integer
Dim NumberWanted As Integer
Dim UserInput As String
Dim i As Integer
Dim NumberOK As Boolean
WriteLine("--------------------------------------------------------------------------------")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| ------------------------------- |")
WriteLine("| {Max and Min number calculator} |")
WriteLine("| ------------------------------- |")
WriteLine("| Press Enter to continue: |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("--------------------------------------------------------------------------------")
WriteLine("Produced and developed by Microsoft Copyright © Microsoft 2015")
WriteLine("--------------------------------------------------------------------------------")
ReadLine()
Clear()
WriteLine(" ------------------------------ ")
WriteLine(" Max and Min number calculator: ")
WriteLine(" ------------------------------ ")
WriteLine()
WriteLine("How many numbers you want to type?")
Do
NumberOK = True
Try
NumberWanted = ReadLine()
If NumberWanted < 1 Then
WriteLine("Error: Number < 1, please enter a number between 1-50.")
NumberOK = False
End If
If NumberWanted > 50 Then
WriteLine("Error: Number > 50, please enter a number between 1-50.")
NumberOK = False
End If
Catch ex As Exception
WriteLine("Error: Please enter a number. ")
NumberOK = False
End Try
Loop Until NumberWanted > 0 And NumberOK = True
Thread.Sleep(1000)
WriteLine("Please enter " & NumberWanted & " numbers of your choice.")
For i = 1 To NumberWanted
WriteLine("Please enter number " & i & ":")
UserInput = ReadLine()
If i = 1 Then
Max = UserInput
Min = UserInput
ElseIf UserInput > Max Then
Max = UserInput
ElseIf UserInput < Min Then
Min = UserInput
End If
Thread.Sleep(100)
Next i
Clear()
WriteLine(" ------------------------------ ")
WriteLine(" Max and Min number calculator: ")
WriteLine(" ------------------------------ ")
WriteLine()
WriteLine("Max = " & Max)
WriteLine("Min = " & Min)
WriteLine("Mean = " & Mean)
WriteLine("Thank you for using the Max and Min number calculator!")
WriteLine("This programm will close in 15 seconds ")
Thread.Sleep(15000)
End Sub
End Module
If anybody has any ideas or suggestions please reply to this thread.
Thanks
The other problem I have is that I want to be able to enter an infinite amount of numbers and type "END" or "-999" into the console to stop entering the numbers. At the moment you are asked how many numbers you want to enter at the start.
Here is the code:
Imports System.Console
Imports System.Threading
Module Module1
Sub Main()
BackgroundColor = ConsoleColor.White
ForegroundColor = ConsoleColor.Black
Clear()
Dim Max As Integer
Dim Min As Integer
Dim Mean As Integer
Dim NumberWanted As Integer
Dim UserInput As String
Dim i As Integer
Dim NumberOK As Boolean
WriteLine("--------------------------------------------------------------------------------")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| ------------------------------- |")
WriteLine("| {Max and Min number calculator} |")
WriteLine("| ------------------------------- |")
WriteLine("| Press Enter to continue: |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("| |")
WriteLine("--------------------------------------------------------------------------------")
WriteLine("Produced and developed by Microsoft Copyright © Microsoft 2015")
WriteLine("--------------------------------------------------------------------------------")
ReadLine()
Clear()
WriteLine(" ------------------------------ ")
WriteLine(" Max and Min number calculator: ")
WriteLine(" ------------------------------ ")
WriteLine()
WriteLine("How many numbers you want to type?")
Do
NumberOK = True
Try
NumberWanted = ReadLine()
If NumberWanted < 1 Then
WriteLine("Error: Number < 1, please enter a number between 1-50.")
NumberOK = False
End If
If NumberWanted > 50 Then
WriteLine("Error: Number > 50, please enter a number between 1-50.")
NumberOK = False
End If
Catch ex As Exception
WriteLine("Error: Please enter a number. ")
NumberOK = False
End Try
Loop Until NumberWanted > 0 And NumberOK = True
Thread.Sleep(1000)
WriteLine("Please enter " & NumberWanted & " numbers of your choice.")
For i = 1 To NumberWanted
WriteLine("Please enter number " & i & ":")
UserInput = ReadLine()
If i = 1 Then
Max = UserInput
Min = UserInput
ElseIf UserInput > Max Then
Max = UserInput
ElseIf UserInput < Min Then
Min = UserInput
End If
Thread.Sleep(100)
Next i
Clear()
WriteLine(" ------------------------------ ")
WriteLine(" Max and Min number calculator: ")
WriteLine(" ------------------------------ ")
WriteLine()
WriteLine("Max = " & Max)
WriteLine("Min = " & Min)
WriteLine("Mean = " & Mean)
WriteLine("Thank you for using the Max and Min number calculator!")
WriteLine("This programm will close in 15 seconds ")
Thread.Sleep(15000)
End Sub
End Module
If anybody has any ideas or suggestions please reply to this thread.
Thanks