62 565
Assignments Done
99%
Successfully Done
In June 2018

Answer to Question #21684 in C++ for islamsaad

Question #21684
write aprogram c++ that read 10 integer value from file and print the sum into another file
Expert's answer

#include <fstream>
#include <iostream>
#include <string>
#include <conio.h>

void read_data();
double sum=0;
using namespace std;
int main()
{
read_data();

getch();
return 0;
}

void read_data(){
string line;
ifstream myfile ("numbers.txt");
int countofline=0;
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);//read each lines
sum+=atof(line.c_str());
}
myfile.close();//cloe file
}
else cout << "Unable to open file

";
cout<<"Sum = "<<sum;
ofstream writefile("sum.txt");
writefile<<sum;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions