Solved

Array help

Posted on 2014-01-13
2
463 Views
Last Modified: 2014-01-13
I want to be able to add the values from an array together. I have placed a random number in a random placement into an array and want to add all of them together but not clear how to?

int i;
for(i=0; i<5; ++i)
{
 
}

I CAN SEE THIS WAY  variable = letters[0]+letters[1]+letters[2]+letters[3]+letters[4];

I would like to learn how to do this using a for statement so I can learn to use them more
0
Comment
Question by:OneNeedingHelp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
Beartlaoi earned 250 total points
ID: 39777674
int Sum = 0;
int i;
for(i=0; i<5; ++i)
{
   Sum += letters[ i ];
}
0
 

Author Closing Comment

by:OneNeedingHelp
ID: 39777678
Thanks now that I see it it is obvious. But I have a question I noticed you made sum an int, but the values in the array are char please explain how this will still work.

Or would it be like this?

char Sum = " ";
int i;
for(i=0; i<5; ++i)
{
   Sum += letters[ i ];
}
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question