Reading from file

Before u say anything
plz i need the code if u ready to show me the code so please
otherwise dont waste ur time and mine thx

i have 2hrs to submit the code
thx

Assume that the following data is stored in file “data.txt”:

2 5 7 1 12 -999

1 4 11 55 66 3 43 23 -999

9 87 56 34 22 12 21 -999

8 7 5 4 6 111 -999

The number -999 at the end of each line acts as a sentinel value and is not part of the data. Write a C++ program that reads these numbers from a file of unspecified length, calculates and displays the sum of all numbers in each line.
Before u say anything
plz i need the code if u ready to show me the code so please
otherwise dont waste ur time and mine thx


I wouldn't be so rude if I was in such a situation...


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
#include<fstream>
using namespace std;

int main(){
fstream f ("data.txt");
int sum=0;
while(f.good()){
int num;
      f>> num;
      if (num==-999){
           cout << sum<< endl; 
           sum=0;
      }
      else sum+=num;
}
return 0;
}
Topic archived. No new replies allowed.