Please send questions to st10@humboldt.edu .
/*-----
  Contract: main: void -> int

  Purpose: a program that helps a user to interactively update values 
           in a file, print the sum of the changed values to the
           screen, and then write the changed values to another file.
  
  Examples: if a file scores.txt contains:
1.1
1.2
1.3
1.4
1.5
            ...and the user runs the program update, entering when
            prompted: 
scores.txt
5
1
27
3
54
-1
newscores.txt
            ...then (interspersed with the prompts) the program
            will print to the screen:
the REVISED values are:
-----------------------
0 - 1.1
1 - 27
2 - 1.3
3 - 54
4 - 1.5

The sum of the new values is: 84.9

            ...and newscores.txt will contain:
1.1
27
1.3
54
1.5

  by: Sharon M. Tuttle 
  last modified: 4-25-07
  -----*/

#include <iostream>
#include "get_file_contents.h"
#include "request_changes.h"
#include "sum_contents2.h"
#include "put_contents.h"
#include "show_indexed_contents.h"
using namespace std;

int main()
{
    const int MAX_LENGTH = 256;
    char infile_name[MAX_LENGTH];
    char outfile_name[MAX_LENGTH];
    int num_values;

    //-----
    // from what file should contents come?

    cout << "what is the input file of numbers? ";
    cin >> infile_name;

    //-----
    // how many values should be read from this file?

    cout << "how many values should be read from " << infile_name 
         << "? ";
    cin >> num_values;

    //-----
    // get file contents

    double values[num_values];
    bool worked = get_file_contents(values, num_values, infile_name);

    if (! worked)
    {
        cout << "get_file_contents failed; goodbye." << endl;
        return EXIT_FAILURE;
    }

    // if get here -- OK to continue

    //-----
    // show current data, and ask for changes

    cout << endl;
    cout << "the current values are: " << endl;
    cout << "------------------------" << endl;
    show_indexed_contents(values, num_values);

    request_changes(values, num_values);

    //-----
    // show users the changed values, and their new sum

    cout << endl;
    cout << "the REVISED values are: " << endl;
    cout << "------------------------" << endl;
    show_indexed_contents(values, num_values);

    double new_sum = sum_contents2(values, num_values);
    cout << endl << "with these changes, the contents' sum is now: "
         << endl << new_sum << endl;

    // where should revised values go?

    cout << "where should revised values go? ";
    cin >> outfile_name;

    worked = put_contents(values, num_values, outfile_name);

    if (! worked)
    {
        cout << "put_contents failed; changes NOT saved." << endl;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}