infile problem

when I read from the file I can not get a string to output. instead it skips the place the string should be and I do not get any of the other information in the file.

INFILE:
Steak 8 oz 420 calories intensity 17 minutes 20
Bananas 4 oz 200 calories intensity 5 minutes 40
Pecans 1 oz 190 calories intensity 12 minutes 24
Salmon 16 oz 625.5 calories intensity 9 minutes 30
Roll 8 oz 317 calories intensity 6 minutes 15
Asparagus 16 oz 56 calories intensity 1 minutes 60
SingaporeSling 8 oz 230 calories intensity 11 minutes 20

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstring>
//Body Weight
using namespace std;
double bmr(double);
double PhysAct(double, double, double);
void format(double);
void read(string, double, string, double, string, string, double, string, double);
double Digest(double, double);
double TotCal(double, double, double);
ifstream infile;
ofstream outfile;
int main()
{
    const double weight = 155.0;
    double inten, time, ounces, cal, BM, PA, TC, DG;
    string food, oz, calories, intensity, minutes;
    infile.open("C:\\Users\\Jacob\\Desktop\\weightdata.txt");
    outfile.open("weightoutput.txt");
    format(weight);
    while (infile)
    {
        read(food, ounces, oz, cal, calories, intensity, inten, minutes, time);
        BM = bmr(weight);
        PA = PhysAct(inten, weight, time);
        DG = Digest(BM, PA);
        TC = TotCal(BM, PA, DG);
        cout << food << "\t\t" << inten << "\t" << time << "\t\t" << BM << "\t\t" << PA << "\t\t" << DG << "\t\t" << TC << endl;
    }
    infile.close();
    outfile.close();
    return 0;
}
void format(double W)
{
    cout << "Weight = " << W << endl;
    cout << "Food\t\tIntensity\tMinutes\t\tBMR\t\tPhysical\tDigestion\tTotal Calories\n";
}
void read(string food, double ounces, string oz, double cal, string calories, string intensity, double inten, string minutes, double time)
{
    infile >> food >> ounces >> oz >> cal >> calories >> intensity >> inten >> minutes >> time;
}
double bmr(double P)
{
    double CalReq = 70 * pow((P/2.2),0.756);
    return CalReq;
}
double PhysAct(double intens, double P, double minut)
{
    double CalNeed = (0.0385 * intens * P * minut);
    return CalNeed;
}
double Digest(double BM, double PA)
{
    double digest;
    digest = ((BM + PA) * .1);
    return digest;
}
double TotCal(double BM, double PA, double DG)
{
    double total;
    total = BM + PA + DG;
    return total;
}
Your first issue is that you should be including "string" not "cstring" on Line 5. "cstring" is for C-Strings as in NULL terminated char array's, it does not have the correct overloads for the insertion or extraction operators.

Besides that you "read()" function should be taking pointers to, not copies of, those variables you're passing to it.
I am not allowed to use pointers
Instead of pointers (and more suitable in this case), consider passing the parameters by reference where necessary.
http://www.cplusplus.com/doc/tutorial/functions/

I see some similarities with another thread - though the file format is a bit different:
http://www.cplusplus.com/forum/beginner/122284/
Setting aside the fact that references may have been the better choice here; why aren't you "allowed" to use pointers? Are you supposed to be typing this with your off-hand while hopping up and down on one foot as well?
passing by reference worked.
and I have not been taught pointers yet.
Topic archived. No new replies allowed.