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
Re: Print the sum of elements, determined by zero elements
Quote:
Originally Posted by
Dimitri
i need print the sum of elements, determined by zero elements.
I have no idea what that means.
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
Re: Print the sum of elements, determined by zero elements
<lightbulb>
I see what the problem is.
Read a line
Split it by semi-colon
Read first value (index 0)
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