2 Replies - 182 Views - Last Post: 19 May 2015 - 03:30 PM

#1 workedmisty  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 16-January 15

Need a Way to Deal with Negative Numbers! (VB)

Posted 19 May 2015 - 02:57 PM

Hello! I am currently working on some code and in it I need the user to enter a number, so firstly I need to check that what they entered is actually a number, then make sure it isn't negative. What I have so far is:
While Not IsNumeric(key)
            Console.WriteLine("Please enter a positive number")
            key = Console.ReadLine()
        End While

        While key < 0
            Console.WriteLine("Please enter a positive number")
            key = Console.ReadLine()
        End While

However, the issue is that once it has checked that it is a number and if they have entered a negative number, it will ask them to reenter the key until it is positive, but won't check if it's a number again. Is there any way to efficiently deal with this? Perhaps combining the loop or some other way to deal with negatives?

Is This A Good Question/Topic? 0
  • +

Replies To: Need a Way to Deal with Negative Numbers! (VB)

#2 workedmisty  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 16-January 15

Re: Need a Way to Deal with Negative Numbers! (VB)

Posted 19 May 2015 - 03:04 PM

Apologies, posted on wrong forum.
Was This Post Helpful? 0
  • +
  • -

#3 Atli  Icon User is offline

  • Enhance Your Calm
  • member icon

Reputation: 3835
  • View blog
  • Posts: 6,304
  • Joined: 08-June 10

Re: Need a Way to Deal with Negative Numbers! (VB)

Posted 19 May 2015 - 03:30 PM

In the future, rather than double posting, please use the "Report" button when such things happen, so that a moderator can move it or otherwise deal with it appropriately.

Closed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1