Here is my code:
#include <iomanip>
#include <fstream>
#include <iostream>
using namespace std;
int main ()
{
ifstream fin;
fin.open("Celsius.txt");
if (!fin.good()) throw "I/O error";
double myC;
fin >> myC;
fin.close();
ofstream fout;
fout.open("Fahrenheit.txt");
if (!fout.good()) throw "I/O error";
double myAnswer = (myC * 1.80) + 32;
fixed;
cout << myC << " Celsius equals " << setprecision(3) << myAnswer << " Fahrenheit" << endl;
fout << myC << " Celsius equals " << setprecision(3) << myAnswer << " Fahrenheit" << endl;
fout.close();
}
Ok, am I just missing some complete fundamental neuron, I seem to have some road block understanding this.
- It’s -2 for formatted input echo, and
- It’s -2 for not formatting output with one decimal digit.
-
Do not format the input values only the output.
fixed; cout << myInput << " should not be formatted, but " << setprecision(3) << myOutput << " should be" << endl;
Doesn’t that stay:
myInput is the unformatted input echo
and myOutput is formatted to one decimal digit?
You must include fixed in the output stream, like so:
setprecision will specify the number of decimal places after the decimal. So 3 will yeild a number like 72.000, or 1 in your case will set it to 72.0