I have some problems in my program. I have to read info from input files and display a message. This is what I have:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void Printing(ofstream& outFile, int& percentFat);
void Percent(float& fatGrams, float& cal, float& fatCal, int& percentFat);
int main()
{
string food;
float fatGrams, cal, fatCal;
int percentFat;
ofstream outFile;
ifstream inFile;
inFile.open("in.dat*");
outFile.open("out.data");
/*getline(inFile, food);
inFile >> fatGrams >> cal;
inFile.ignore('/n');*/
while(inFile)
{
getline(inFile, food);
inFile >> fatGrams >> cal;
inFile.ignore('/n');
fatGrams =+ fatGrams;
cal += cal;
outFile << "You ate "<< food << endl
<< "Which had " << fatGrams << " grams of fat and " << cal << " calories" << endl;
}
}
void Printing(ofstream& outFile, int& percentFat)
{
if (percentFat < 30)
outFile << "Congratulations! You had a Heart Healthy Meal." << endl;
else
outFile << "Warning! You had too many fat calories." << endl;
}
void Percent(float& fatGrams, float& cal, float& fatCal, int& percentFat)
{
fatCal = fatGrams*99;
percentFat = int((fatCal/cal)*100);
}
My problem here is that I don't know how to use the getline and ignore function.Here is how one of the input files lookks like:
Egg McMuffin with orange juice and coffe
11
360
Chunky chicken salad with iced tea
6
198
Regular hamburger with small fries and Diet Coke
21
476