So it is a simple problem. Simply read input from a specific file. Use the input as a Celsius temperature and convert this temperature into Fahrenheit then print the results to the user.
The problem seems to occur when I try to save input from the file. Located in the while block. I get an error I know may be caused by trying to use an int value in getline. I am fairly new to c++ and not sure how to do this. I have tried a myriad of ways but none seem to work. Any help would be greatly appreciated!
I did #include <fstream>
.
The file contains these three values '0 50 100'.
This is the section of the code I have been working with:
//values for the files three input values
int i = 0, inVal1 = 0 , inVal2 = 0, inVal3 = 0,
farenheit1 = 0, farenheit2 =0,farenheit3 = 0;
ifstream inFile; //Input file variable
inFile.open("celsius_input.dat"); //open the file
if(!inFile){
cout << "Unable to open file";
exit(1); //terminate with error
}//end if
while (inFile)
{
cin.ignore();
getline(inFile, inVal1);
getline(inFile, inVal2);
getline(inFile, inVal3); // read the files values
inFile.close();//Close file
} //end while
farenheit1 = (9.0/5.0) * inVal1 + 32.0; //formula
farenheit2 = (9.0/5.0) * inVal2 + 32.0; //formula
farenheit3 = (9.0/5.0) * inVal3 + 32.0; //formula
cout << "The first Inputed Value, " << inVal1
<< " degrees, Converted Into Farenheit Is "
<< farenheit1 << " Degrees!" << endl; //output of results
cout << " " << endl;
cout << "The Second Inputed Value, " << inVal2
<< " degrees, Converted Into Farenheit Is "
<< farenheit2 << " Degrees!" << endl; //output of results
cout << " " << endl;
cout << "Teh Third Inputed Value, " << inVal3
<< " degrees, Converted Into Farenheit Is "
<< farenheit3 << " Degrees!" << endl; //output of results
cout << " " << endl;