# Thread: Print the sum of elements, determined by zero elements

1. Member
Join Date
Sep 2011
Posts
6
Rep Power
0

## Print the sum of elements, determined by zero elements

Hello, guys.
I have next csv file:
3;qw;4;5.1;2.7
15;;;k;5
1;3.14;fgh;5
0;;e1;2;3
-2.3;a;b;c
b;d;e

And i added this data from file to String array[][] and i need print the sum of elements, determined by zero elements. Create this result in the string. The output format see in the example: sum = 5.1 + 3.14 + 0 = 8.24

How do I do, I understand the algorithm, but the syntax does not know. Please, help

2. ## Re: Print the sum of elements, determined by zero elements

Originally Posted by Dimitri
i need print the sum of elements, determined by zero elements.
I have no idea what that means.

3. Member
Join Date
Sep 2011
Posts
6
Rep Power
0

## Re: Print the sum of elements, determined by zero elements

File in.csv (text data separated by semicolon) contains some sequence of lines with any number of elements in each line.
Let the initial element of any line has an index 0. Its value determines the index of an element in the line you should work with.
1) Print the sum of elements, determined by zero elements. Create this result in the string. The output format see in the example below.
2) Print the number of lines with “errors”.

The example of the file in.csv:
3;qw;4;5.1;2.7
15;;;k;5
1;3.14;fgh;5
0;;e1;2;3
-2.3;a;b;c
b;d;e
Output:
sum = 5.1 + 3.14 + 0 = 8.24
error-lines = 3

4. ## Re: Print the sum of elements, determined by zero elements

<lightbulb>
I see what the problem is.

Split it by semi-colon
Check to see if value is valid (positive and less than length)
If it is valid use it as index into array and add value at that index to sum
Else increment error count

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•