Respuesta :

Answer:

The solution code is as follows:

  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5. int main()
  6. {
  7.    ifstream data;
  8.    float number;
  9.    float sum = 0;
  10.    
  11.    data.open("numbers.txt");
  12.    
  13.    while (data >> number) {
  14.        sum = sum + number;
  15.    }
  16.    cout<<sum;
  17.    return 0;
  18. }

Explanation:

Firstly, we create a ifstream object, data (Line 9). Then we can use the ifstream object to open the "numbers.txt" (Line 13) and use while loop to traverse through the number in the text file line by line (Line 15). White the loop is ongoing the number in each line is read by >> operator in a similar way to cin and then add each read number to sum variable (Line 16).

At last, display the output (Line 18).