help with a beggining program here is my code.
Can you help me with this program please Im suppose to sum the numbers from a file but Im getting a wrong output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int numbers, sum, count;
sum = 0;
string inputfile;
cout << "path of file : ";
getline(cin, inputfile);
ifstream infile (inputfile.c_str());
if (infile.is_open()) {
for (int i = 0; i < 5; ++i)
{
infile >> numbers;
sum += numbers;
++count;
cout << sum << endl;
}
} else {
cout << "Error" << endl;
}
infile.close();
return 0;
}
|
Topic archived. No new replies allowed.