Instructions : Read a series of lines from a text file, get the numeric values in each line, perform addition and display sum
and this is my code
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
int sum = 0;
char x[50];
double d;
ifstream inFile;
inFile.open("input.txt");
while(inFile.getline(x,50)) {
cout<<x<<endl;
d=atof(x);
sum+=d;
cout<< sum << endl;
}
}
system("pause");
}
and the text from the file is
hello51.20world10.00again
40programming
file 20editsearch50 project.15
the output should be
hello51.20world10.00again
61.2
40programming
40
file 20editsearch50 project.15
70.15
can u help me? just give me the algorithm to sum and the string function to use