Need help with using ifstream in functions

I basically just want to take the below data, and use a function to store all of the information, and then another function to output it. So far, I'm only getting one error (even though I'm sure I have more), that in the "GetData" function definition, "fileIn" was not declared in the scope. If someone could steer me in the right direction, I would appreciate it...

Also, kind of off-topic, I definitely understand the differences between passing by value and reference, but when I start to deal with a lot of data/variables, I get confused as to what I should make a reference, and what I shouldn't. I probably just need more experience with it, but if someone could give a good rule of thumb, it would be appreciated, as well.

Thanks!!

INPUT:

10 0 S Y 100.00
27 3 D Y 57.50
125 17 D N 0.00
4 0 S N 25.00
0 25 S Y 23.75
250 43 D N 500.00
0 0 D N 0.0
10 0 R Y 10.00
17 3 D R 15.00
5 0 D Y 275.00
-3 10 D Y 20.00
14 -1 S N 30.00
20 3 D Y -10.00

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
#include <iostream>
#include <fstream>
 
using namespace std;
 
void GetData(int &, int &, char &, char &, double &);
void outputData(int, int, char, char, double);
 
int main()
{
 
    int numAdults, numChildren;
    char mealType, dayType;            //mealType - standard or deluxe;
    double mealDeposit;                //dayType - is it a weekend, or not.
 
    ifstream fileIn;
 
    fileIn.open("file.txt");
 
 
    if (!fileIn) {
	cout << "Cannot open file, terminating program" << endl;
    }
    while (fileIn) {
 
	GetData(numAdults, numChildren, mealType, dayType, mealDeposit);
 
    }
 
    outputData(numAdults, numChildren, mealType, dayType, mealDeposit);
 
 
    fileIn.close();
 
 
    return 0;
}
 
void GetData(int &numAdults, int &numChildren, char &mealType, char &dayType, double &mealDeposit)
{
 
    fileIn >> numAdults >> numChildren >> mealType >> dayType >> mealDeposit >> endl;
 
}
 
void outputData(int numAdults, int numChildren, char mealType, char dayType, double mealDeposit)
{
 
    cout << numAdults << numChildren << mealType << dayType << mealDeposit << endl;
 
}
 
Topic archived. No new replies allowed.