so i have written a chunk of code to take in data from a txt file then perform some calculations on it. However, i am trying to print the original contents of the txt file to the screen before the the rest of the function executes and I am running into some problems. it either doesnt print to the screen or it makes my output file empty or only displays one line. any help about what to do would be greatly appreciated!
#include fstream
#include iostream
#include iomanip
#include string
using namespace std;
int main()
{
// defines the input/out streams for the data file
ifstream dataIn;
ofstream dataOut;
// Contains amount item purchased
int a, b, t, noOfDishes;
int res, res1;
string inputfile;
cout << "Please enter the name of the file you want to open:" << endl;
getline(cin, inputfile);
// Opening the input file
dataIn.open(inputfile);
cout << infile1.rdbuf();
// checking whether the file name is valid or not
if (dataIn.fail())
{
cout << "** File Not Found **";
return 1;
}
else
{
// creating and Opening the output file
dataOut.open("output.txt");
while (dataIn >> a >> b >> t)
{
res = 0;
noOfDishes = 0;
dataOut << a << "\t" << b << "\t" << t << "\t";
res1 = a;
res = a;
while (true)
{
if (res <= t)
{
noOfDishes++;
res1 = (res1 + b);
res += res1;
}
else
break;
}
dataOut << noOfDishes << endl;
}
// Closing the input file
;
dataIn.close();
cout << " Data Written to output.txt " << endl;
// Closing the output file.
dataOut.close();
}
return 0;
}