Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Some help...

Some help...

Scheduled Pinned Locked Moved Visual Basic
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adam Wike
    wrote on last edited by
    #1

    How would I get a program to show the numbers it adds up? Say the user wants the program to add numbers 1 through 10. How would I get the result to show up as "1+2+3+4+5+6+7+8+9+10=55"? I dont have a problem getting the program to add the numbers or anything. I just need help displaying the result, if it's any help I'll be using a loop. If I havent explained myself well enough let me know. Thanks :)

    rawr!

    L A 2 Replies Last reply
    0
    • A Adam Wike

      How would I get a program to show the numbers it adds up? Say the user wants the program to add numbers 1 through 10. How would I get the result to show up as "1+2+3+4+5+6+7+8+9+10=55"? I dont have a problem getting the program to add the numbers or anything. I just need help displaying the result, if it's any help I'll be using a loop. If I havent explained myself well enough let me know. Thanks :)

      rawr!

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      you want the output to contain two things: a string representing the operands and operations, and the evaluation result. Hence your loop should contain two things: a concatenation adding the latest operator and operand to the symbolic string, and an addition adding the addend to the partial sum. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      Prolific encyclopedia fixture proof-reader browser patron addict?
      We all depend on the beast below.


      1 Reply Last reply
      0
      • A Adam Wike

        How would I get a program to show the numbers it adds up? Say the user wants the program to add numbers 1 through 10. How would I get the result to show up as "1+2+3+4+5+6+7+8+9+10=55"? I dont have a problem getting the program to add the numbers or anything. I just need help displaying the result, if it's any help I'll be using a loop. If I havent explained myself well enough let me know. Thanks :)

        rawr!

        A Offline
        A Offline
        Andy_L_J
        wrote on last edited by
        #3

        Module Module1

        Sub Main()
        
        Dim txt As String = ""
        Dim arr() As Double = {20, 11, 34, 25, 55, 89}
        Dim tot As Double = 0
        
        For i As Integer = 0 To 5
          If i < 5 Then
            txt &= arr(i).ToString("0")
            txt &= "+"
            tot += arr(i)
        
          Else
        
            txt &= arr(i)
            txt &= "="
            tot += arr(i)
            txt &= tot.ToString("0")
          End If
        
        
        
        Next
        
        Console.WriteLine("Output: {0}", txt)
        Console.Read()
        End Sub
        

        End Module

        I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups