Results 1 to 5 of 5

Thread: Can someone help answer this 4 questions? I'm using MS Visual Basic 2010

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2021
    Posts
    2

    Can someone help answer this 4 questions? I'm using MS Visual Basic 2010

    1. Write VB.NET code that will use a loop to calculate the sum of all integer numbers between 5 and 100 that are divisible by both 5 and 6.
    You may choose to use any looping structure.

    Use the following variable declarations.

    Dim intCounter As Integer ‘loop counter variable

    Dim intSum As Integer ‘to accumulate the summation

    2. Study the following code. what messages will be displayed in the message box?

    Dim intCounter As Integer

    Dim dblSum As Double, dblNumber As Double

    dblSum = 0

    intCounter = 1

    Do While intCounter < 6

    dblSum = dblSum + Convert.ToDouble(intCounter)

    If intCounter Mod 3 = 0 Then

    dblNumber = 5.0

    End If

    dblSum = dblSum + dblNumber

    intCounter = intCounter + 2

    Loop

    MessageBox.Show("The Sum is: " & dblSum.ToString(),"IS122")

    3. Rewrite the following section of code using a For Next loop instead of a Do While loop.

    Dim intSum As Integer

    int intCount As Integer

    intCount = -5

    Do While intCount <= 15

    intSum = intSum + intCount

    intCount = intCount + 1

    Loop

    4. Consider the same Do While loop in question 4 above to answer the following questions:
    (a) How many times the loop condition is tested?

    (b) How many times the body of the Do While loop is executed?

    (c) What is the final value of intSum and intCount variables after the loop ends?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,466

    Re: Can someone help answer this 4 questions? I'm using MS Visual Basic 2010

    1.

    Code:
    Dim intSum As Integer = 0
    For intCounter as integer = 5 to 500
        If intCounter Mod 5 = 0 and intCounter Mod 6 = 0 Then intSum += intCounter 
    Next
    2.

    Write the code and check the outputs in the IDE

    3.

    ...

    4.

    Write the code and check the outputs in the IDE. Use breakpoints and stepping

  3. #3
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: Can someone help answer this 4 questions? I'm using MS Visual Basic 2010

    @.paul. it is not like that that you will get a good mark and your degree
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,466

    Re: Can someone help answer this 4 questions? I'm using MS Visual Basic 2010

    Quote Originally Posted by Delaney View Post
    @.paul. it is not like that that you will get a good mark and your degree
    You can lead a horse to water...

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Can someone help answer this 4 questions? I'm using MS Visual Basic 2010

    I think you should have used a timer for the first one. After all, the question states that you can use ANY looping structure, and a timer is a looping structure.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width