beginner here need help with an array code

This is a discussion on beginner here need help with an array code within the C++ Programming forums, part of the General Programming Boards category; hey im a beginner to C++ and I'm looking for a bit of help in one of my programs, I ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    3

    beginner here need help with an array code

    hey im a beginner to C++ and I'm looking for a bit of help in one of my programs, I havent done much with arrays in C++ but I'm looking to get an array of 10 randomly assigned integers, find a way to add them together and print out the result, as well as add all the numbers of the even index of the array and subtract all the numbers in the odd index of the array and put those in two different results. Can someone walk me through this?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Right. The homework policy here at Cprogramming.com is that you show us what you've done and we will help you - not "Post your homework assignment and someone will post back the answer".

    -.
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    3
    sorry
    Last edited by Ohshtdude; 02-01-2009 at 07:07 PM.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you are dealing with a[i], how can you tell whether i is even or odd?

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    3
    no like a[0] being even a[1] being odd a[2] being even etc

  6. #6
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    how about adding 2 in each iteration?

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Ohshtdude View Post
    no like a[0] being even a[1] being odd a[2] being even etc
    Right. So how do you know that 0 is even, 1 is odd, 2 is even, etc?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. array of pointers/pointer arithmetic
    By tlpog in forum C Programming
    Replies: 18
    Last Post: 11-09-2008, 06:14 PM
  3. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  4. beginner: dynamic array of strings
    By pc2-brazil in forum C++ Programming
    Replies: 10
    Last Post: 04-29-2008, 04:29 PM
  5. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 08:51 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21