Hello, I'm trying to create a program that reads data from outside file using functions. My goal is to get data from an outside file, and use that data for other functions that i havent created yet. this is my code so far but it wont read and giving me output errors.
PLease help, thanks so much!
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
ifstream infile;
ofstream outfile;
int noOfAdults, noOfKids;
float deposit;
string mealType;
bool weekend;
void getData ();
int main()
{
infile.open ("C:\\Users\\garu525\\Desktop\\CateringDatafile.rbh");
if (!infile)
{
cout << "File not found. Exiting. . ." << endl;
exit(1);
}
outfile.open ("C:\\Users\\garu525\\Desktop\\CateringBill.rbh");
while (!infile.eof())
{
getData ();
}
cout << fixed << showpoint << setprecision(2);
cout << noOfAdults << '\t' << noOfKids << '\t' << mealType << '\t' <<weekend << '\t' << deposit << endl;
infile.close();
outfile.close();
system ("pause");
return 0;
}
void getData ()
{
infile >> noOfAdults >> noOfKids >> mealType >> weekend >> deposit;
cout << noOfAdults << noOfKids << mealType << weekend << deposit;
if (noOfAdults < 0 || (!infile)) outfile << "Error on number of Adults data.";
if (noOfKids < 0 || (!infile)) outfile << "Error on number of Children data.";
if (mealType != "S" || "D") outfile << "Error on Meal type data.";
if (mealType == "S") mealType = "Standard";
if (mealType == "D") mealType = "Deluxe";
if (!weekend) outfile << "Error on weekend data";
if (deposit < 0) outfile << "Error on Deposit data";
}