visual basic

posted by .

Program that i am having trouble with having hard time how to figure out to assign non-zero digit to a variable!

Create a variable first as integer 
Assign first non‐zero digit of your V‐number to the variable first 
Create a variable last as integer 
Assign last non‐zero digit of your V‐number to the variable last 
Multiply first number last times
Display the result 


Dim first As Integer
Dim last As Integer
Console.WriteLine(" Enter in your V number ")
first = Console.ReadLine
last = Console.ReadLine

  • visual basic -

    Perhaps the most useful tip you can know in learning to program, though you won't find it in a book, is to ask for help, giving _all_ information about the problem, whether you think it's useful of not! :-)

    You've posted the problem code. This is good. You haven't specified what the error appears to be, nor which version of VB you're using. This is not so good, because we have to guess a bit.

    When posting on technical forums, other programmers will often look at such a question, think "insufficient information to draw a conclusion" and not answer. They have lots to do, and they're usually not going to post a question and wait for you to get around to answering, so that they can consider the question again. Don't give them that excuse!

    Microsoft have changed VB quite a bit between versions, and without knowing which version, and what error, exactly, the compiler is giving you, or what wrong result your program is coming up with, there's a wide field to choose from - though MathMate may have a better understanding of where you're at. :-)

    For me, reading that, I would first suspect your use of Console.ReadLine in two ways:
    1. Should it be Console.ReadLine() or Console.ReadLine(name_of_stream_to_read)?
    2. What does Console.ReadLine return? You've declared first and last as integers, but readline type functions commonly return strings.

    Your "non-zero" remark makes me think maybe the program is working, but always leaving you with zero in first and last? If so, it could be that Console.ReadLine is returning a string, so the value isn't getting into the integer; you need to get the string's value before you can assign it.

    Maybe.

    You might check your language reference help for the formal definition of Console.ReadLine and see what it is actually doing.

  • visual basic -

    I just read your question again, and I now think that, given an input string, you want to find the first non-zero digit in it. Though again, I could be wrong.

    So if the input is "A046", you want "4", and if it's "0.0029x" you want "2".

    If that's the question, then your approach should be:

    1. Read in a string.
    2. Using a loop, read each character along the string from left to right until you come to a digit "1" through "9" inclusive.
    3. Return that digit, or capture it in a variable.

    I used the very verty old version of BASIC on my PC to write this up:

    Print "Enter a string containing at least one digit 1 through 9"

    input Instring$

    REM starting at the left, walk along the string until we find what we're looking for

    posn=1

    while (posn < len(Instring$) and (mid$(Instring$, posn,1)<"1" or mid$(Instring$, posn,1)>"9"))
    posn=posn+1
    wend

    REM posn is now either pointing to what we want, or there isn't one
    REM we need to distinguish between the two cases

    if mid$(Instring$, posn,1)>="1" and mid$(Instring$, posn,1)<="9" then
    print "We got one - ";mid$(Instring$, posn,1)
    else
    print "there isn't a usable digit here!"
    end if

  • visual basic -

    sorry for not gving enough information but i did end up getting it.

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. discrete math

    1)prove that if x is rational and x not equal to 0, then 1/x is rational. 2) prove that there is a positive integers that equals the sum of the positive integers not exceeding it. Is your proof constructive or nonconstructive?
  2. programming

    I am supposed to modify this program so it begins by asking the user for the number of values. The program then uses a loop to read the specified number of values and then display their average. program is below that i worked on in …
  3. visual basic

    Im trying to get this program to average three number having a problem the sample nmubers im using are 6 6 2 average supposed to be 4.6667 but im just geting .6667 I think it has something to do with my s=value(i) not sure what i need …
  4. Math

    The tens digit of a two-digit positive integer is 2 more than three times the ones digit. If the digits are interchanged, the new number 13 less than half the given number. Find the given integer. (Hint: Let x = tens-place digit and …
  5. programming

    There are several types of room in a hotel. The HotelRoom Class of Previous Programming Problem was not specific regarding the type of room. Assume that a hotel has guest rooms and meeting rooms. Modify the HotelRoom class as follows: …
  6. PROGRAMMING

    1. Make a C program that will input two integers and then to enter an option as follows: • 1 = to add the two integers. • 2 = to subtract the second integer from the first. • 3 = to multiply the integers • 4 = to divide the …
  7. Computer Science

    Create a program that allows a user to select one of the following four menu options: a. Enter New Integer Value b. Display Pointer Address c. Display Integer Address d. Display Integer Value For this program you will need to create …
  8. Algebra

    Solve algebraically using one variable: Find three consecutive odd integers such that the product of the first integer and the third integer is equal to nine more than twelve times the middle integer.
  9. Algebra

    Solve algebraically using one variable: Find three consecutive odd integers such that the product of the first integer and the third integer is equal to nine more than twelve times the middle integer.
  10. Algebra Word Problem

    Solve algebraically using one variable: Find three consecutive odd integers such that the product of the first integer and the third integer is equal to nine more than twelve times the middle integer.

More Similar Questions