Solved

Array help

Posted on 2014-01-13
2
444 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
Comment Utility
int Sum = 0;
int i;
for(i=0; i<5; ++i)
{
   Sum += letters[ i ];
}
0
 

Author Closing Comment

by:OneNeedingHelp
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

772 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