CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2012
    Posts
    5

    enerting double values into a array

    hey guys,
    i have been struggling for hours now on how to enter double values into my array so that it can output the sum of the numbers less than 24. this is my code so far. and im stuck


    #include <iostream>


    using namespace std;

    int main()
    {
    double positive_values[10];
    double[] positive_values = {2, 57, -4, 7, 19, 23, 3, 9, 15, 44};

    double sum = 0;

    }

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: enerting double values into a array

    double positive_values[] = {2, 57, -4, 7, 19, 23, 3, 9, 15, 44};

  3. #3
    Join Date
    Aug 2012
    Posts
    5

    Re: enerting double values into a array

    i ran the program and its telling me der are too many initializers

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: enerting double values into a array

    Then you didn't follow GCDEF's example. Cut & paste the example into your code overwriting your old code.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: enerting double values into a array

    You have two choices:
    Code:
    double positive_values[10];
    
    positive_values[0] = 2;
    positive_values[1] = 57;
    ...
    positive_values[9] = 44;
    or
    Code:
    double positive_values[] = {2, 57, -4, 7, 19, 23, 3, 9, 15, 44};
    Be careful where you put the brackets []. It's not after the type (like in C#), but after the variable.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Tags for this Thread

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