#include <fstream> #include <iostream> #include <cmath> using namespace std; int main () { ifstream InFile; ofstream OutFile; int num; int diff; int closest; InFile.open("E:\\CFiles\\DataFile2.txt"); OutFile.open("E:\\Answers.txt"); InFile>>num; closest=num; diff=abs(num-200); while (InFile) { InFile>>num; if (abs(num-200<diff)) //Sets condition { closest=num; } } cout<<"The closest value is= "<<num<<endl; InFile.close(); // I was asked to include this code by instructor InFile.clear (); } |