Hey again! ;)
This time I have this program which is supposed to read some stream file called "numbers.dat" which has the numbers 1 up to 10.
I get the reading, but the thing is in the for loop I want to add the numbers in circles.
For example:
1 2 3 4 5 6 7 8 9 10
I want the number 1 and number 10 to be added, then number 2 and number 9 to be added.
This addition I want to write it in the stream file called "numbers2.dat"
The program does add the numbers, but in parallel: 1+2 = 3, then 3+4=7
Here is the code.
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main() {
int size = 100;
int pos = 0;
int largo = 0;
int dato, dato2, circulo, i;
int array[size];
ifstream read("numbers.dat");
ofstream write("numbers2.dat");
read >> dato >> dato2;
while (!read.eof()) {
array[pos] = dato; // first number of the file
array[size-pos-1]= dato2; // last number of the file
pos++;
largo += 2; // how many elements are in the file
read >> dato >> dato2;
}
circulo = largo/2; // the actual number of circles
write << "LA SUMA DE TODOS LOS CIRCULOS ES: " << endl;
for (i = 0; i <= circulo; i++) {
write << "\ncirculo # " << (i+1) << ": " << dato+dato2; // write to "numbers2.dat" the addition in circles
}
return 0;
}
So, could you guys give me a hint or is there some way to make the addition in circles? I think I have it already but there's some kind of mistake somewhere. Thanks!