Solved

Array help

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.

751 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