I am writing a simple code that is supposed to input temperatures from a .txt file, convert them to Celsius, and then output the Celsius to another .txt file. My main problem occurs in the " while (inFile >> fnum) { " portion of the code below. I am able to input the numbers from File1.txt, but when it goes to convert them, it doesn't seem to like doing division. If I take out the " (5 / 9) " portion of the conversion, it will input the number, minus the 32, and output the resulting number. When I leave the " (5 / 9) " portion in, all it does is out 0s. Any help is appreciated.
The numbers I used in the inFile.txt file are irrelevant. They just need to be 10 numbers that it can reference.
What I have so far:
The numbers I used in the inFile.txt file are irrelevant. They just need to be 10 numbers that it can reference.
What I have so far:
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inFile;
ofstream outFile;
int fnum;
int cnum1;
float cnum;
int x;
inFile.open("File1.txt");
if (inFile.fail()) {
cerr <<"The file was not able to open." << endl;
exit(1);
}
while (inFile >> fnum) {
//This should be something like, cnum = ((fnum - 32) * (5 / 9))
cnum = 5 / 9;[/b]
cnum1 = (fnum - 32);
x = cnum * cnum1;
cout << "Temperature = " << x << " " << endl;
}
outFile.open("File2.txt");
outFile << x << endl;
outFile << "\nThis is the end of the of the file";
inFile.close();
outFile.close();
return 0;
}