Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Visual Logic Problem, Please Help!


  • Please log in to reply

#1
megan1989

megan1989

    New Member

  • Member
  • Pip
  • 1 posts
Write a program that reads in a list of positive integers from the user
until the user enters the value –1 as a sentinel. At that time the program should display the largest value in the input list.

So I think I have the first part figured out, ending when you input -1. The problem that I am having is figuring out how to make the visual logic program give me the largest value at the end of the loop. Anyway this is what it looks like:

Begin:
Input: Number (and in the input statement I have it saying "Pick a Number")
While Statement: TRUE>true (I have nothing routing into the false)
From the true statement it goes into a IF statement
IF Statement: Number = -1> if true it goes to OUTPUT: "The largest Number was "
and if it is false to create a loop I put another input statement
INPUT: Number (and in the input statement it again says "Pick a Number")

I know that it can't be too complicated, I am probably just overthinking it.

 

But I have figured out to get the largest number to display I need to create a loop to check and see if the entered number is larger than the previous number being entered, but I don't know how to work that into my current program or even how to accomplish that.  Presently there is nothing being outputted to output of "the largest number is" If anyone can help me figure this out I would greatly appreciate it. thanks


  • 0

Advertisements


#2
Aura

Aura

    Special Ops

  • Malware Removal
  • 2,563 posts
Usually, what I do is this :

Define a variable "highest" that is set to 0.
Then you do a loop through the list of numbers (integers). Every time, you verify if the integer you check is bigger than the number in the "Highest" variable. If it is, you replace the "highest" value with the value of the integer you just checked. At the end, you'll have the highest value that was passed in the list.

If you want, I can make you an exemple in C# tonight so you understand better and can see the logic.
  • 1

#3
ruggie_uk

ruggie_uk

    Trusted Helper

  • Malware Removal
  • 2,083 posts

While Aura is sleeping, I knocked up a little visual basic program to do what you are looking for - you should be able to follow what it does based on your psuedocode.

 

I am not a great programmer so it probably isn't the most efficient code but here it is

    Sub Main()
        Dim number = 0
        Dim highnum = 0
        Dim lastnum = 0


        While number <> -1
            Console.WriteLine("input a number")
            number = Console.ReadLine
            If number > highnum Then
                highnum = number
            End If
            If number < lastnum Then

                Console.WriteLine("Last number was higher")
            Else
                Console.WriteLine("Last number was lower")

            End If
            lastnum = number
        End While

        Console.WriteLine("The Highest number was " + highnum.ToString)
        


    End Sub

End Module

Edited by ruggie_uk, 31 July 2014 - 06:34 AM.

  • 0

#4
Aura

Aura

    Special Ops

  • Malware Removal
  • 2,563 posts
Ruggie got the logic I explained totally right in his code, good job Ruggie :)
  • 0

#5
ident

ident

    Member

  • Member
  • PipPipPip
  • 745 posts

If you are targetting 3.5 + use array.max

Public Class Form1

    ' this is just for an example to generate the list.
    Private ReadOnly Rng As New Random

    Private Sub Foo()
        Dim numbers As Integer() = Enumerable.Range(0, 100).Select(Function(n) Me.Rng.Next(0, 100000)).ToArray
        Dim highest As Integer = numbers.Max

        MessageBox.Show(highest.ToString)
    End Sub

End Class


  • 0

#6
ident

ident

    Member

  • Member
  • PipPipPip
  • 745 posts

Ok now i see more clearly. Please go into properties and turn option strict on. The code suggested will not compile and does not check if the value is a integer.


  • 0

#7
ident

ident

    Member

  • Member
  • PipPipPip
  • 745 posts

By the way it's good practise to post what you have tried first. Regardless if it works or not.


  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP