Solved

Array help

Posted on 2014-01-13
2
446 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The viewer will learn how to implement Singleton Design Pattern in Java.

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now