CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2015
    Posts
    15

    Findig Average in Array of Number

    Hello, I am creating an average application that calculates the average of a set of numbers from 1 to the number the user has input. For example, if the user enters 5, the average of 1,2,3,4,5 would be calculated. If someone could help me out with the code that would be great!

    Thanks

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Findig Average in Array of Number

    You simply add the values together then divide by the number of entries.
    I'm not sure where an array comes into it as your post sounds like you just need a simple for next loop with a little math, no reason to use an array.

    Try it yourself, ask questions if you are stuck but do not expect someone to write the code for you.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Nov 2015
    Posts
    15

    Re: Findig Average in Array of Number

    I do not think it is that simple because the label should, for example they could type in any number. The label should not just read the answer but it should say the numbers from 1-5(or any number they type in) is 3(the average of those numbers.)

    Our prof said we need to use strings for this problem, but I don't know how to grab their string/number they type in and display that in the label.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Findig Average in Array of Number

    It is that simple, You have to get what the user types of course and to display that in a label is about as simple as it gets. i.e. Label1.Text=TheValue.ToString

    To build the string you mention you have to put some values together. for example one way would be
    Code:
    Label1.Text="The average of numbers from 1 to " & TheValue.ToString & " is " & TheAverage.ToString
    How you would get what they enter depends on the method you use to allow them to enter it.
    Last edited by DataMiser; November 12th, 2015 at 07:05 AM.
    Always use [code][/code] tags when posting code.

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

Featured