// Attached: Lab_6 Program #1
// ===========================================================
// File: Lab6_Program1.cpp
// ===========================================================
// Programmer: Elaine Torrez
// Class: CS 1A
// ===========================================================
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
// ==== main ===================================================
// This program writes one number to a text file twice.
// The first output writes the number normally.
// The second output formats the number to two decimal places.
//
// Input:
// No user input.
//
// Output:
// The number is written to the file values.txt twice,
// once unformatted and once formatted to two decimal places.
// ===========================================================
int main()
{
fstream dataFile;
double number = 17.816392;
// open the file for output
dataFile.open("values.txt");
// format for fixed-point notation
dataFile << fixed;
// write number without limiting decimal places
dataFile << number << endl;
// format output to 2 decimal places
dataFile << setprecision(2);
// write number again
dataFile << number << endl;
cout << "Data has been written to file.\n";
// close the file
dataFile.close();
return 0;
} // end of main()
// ===========================================================