Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Array help

Posted on 2014-01-13
2
Medium Priority
?
470 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

730 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