/* Filename:  makegradefile.cpp

   Author:  Br. David Carlson

   Date:  October 25, 2004

   This program reads floating point GPAs (0.00 to 4.00) from the keyboard
   and writes them to the gradefile.txt text file, one per line.  The numbers
   should be entered one at a time, as prompted.  The numbers are written to
   the file with exactly 2 decimal places.  Use CTRL z to end data input
   when using Visual C++ on a PC.  You may need to press ENTER a couple
   of times.  However, this must be changed to using CTRL d when using g++
   under Linux, as CTRL d is the Unix/Linux end of file.

   Tested with:
      Microsoft Visual C++ 6.0
      Microsoft Visual C++ .NET
      g++ under Linux
*/

#include <iostream>
#include <fstream>
#include <iomanip>   // in order to use setw
using namespace std;


int main(void)
   {
   float Num;
   fstream OutFile;

   OutFile.open("gradefile.txt", ios::out);
   if (OutFile.fail())
      {
      cout << "Open of gradefile.txt failed" << endl;
      exit(1);
      }

   // Set up output file formatting:
   OutFile.setf(ios::fixed);
   OutFile.setf(ios::showpoint);
   OutFile.precision(2);

   // Warning: Change this to CTRL d for Linux:
   cout << "Enter a GPA number (or CTRL z to end): " << endl;
   cin >> Num;

   while (! cin.fail())
      {
      // Process the data:
      OutFile << setw(12) << Num << endl;
      // Warning: Change this to CTRL d for Linux:
      cout << "Enter a GPA number (or CTRL z to end): " << endl;
      cin >> Num;
      }

   OutFile.close();
   
   return 0;
   }

