Line keeps disapearing

Class assignment
food appears of different line when outputted
I have changed the code to run the report once to make diagnosint the problem easier

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

int main()
{
ifstream infile;
ofstream outfile;
infile.open ("food.txt");
outfile.open ("fatreport.txt");
int cal,fatCal;
float fatGrams;
float fatPercent;
string food;
const char lowFat='*';


//collumns
int col1=40,col2=15,col3=15,col4=15;

outfile
<<left
<<setw(col1)<<"Food Description"<<setw(col2)<<"Calories"<<setw(col3)<<"Fat Calories"<<setw(col4)<<"Percent Fat"<<endl;


infile >> cal >> fatGrams;
infile.ignore();
getline (infile,food);



if (cal != 0)
{
fatCal=fatGrams*9;
fatPercent=static_cast<float>(fatCal)/cal*100;
}
else
{

fatPercent=0;
}

if (fatPercent <= 30)
food = lowFat+food;

outfile

<<left
<<setprecision (1)<<fixed
<<setw(col1)<<food<<setw(col2)<<cal<<setw(col3)<<fatCal<<setw(col4)<<fatPercent<<endl<<endl;


infile >> cal >> fatGrams;
getline (infile,food);


outfile<<"\t* Low fat foods";



return 0;

}




Last edited on
Output looks like:

Food Description Calories Fat Calories Percent Fat
1/4 pound hamburger
328 211 64.3

* Low fat foods

food.txt looks like:

328 23.5 1/4 pound hamburger
186 1.5 Raisin Bran
0 0 Diet Sprite
117 5 cottage cheese - 1/2 cup
200 14 swiss cheese - 2 oz.
183 11 Tofu, firm - 1/2 cup

Topic archived. No new replies allowed.