error C2065: 'outfile' : undeclared identifier Help.

Someone please look and at my code and show how i need to fix this.

Write a program to calculate and generate receipts for a grocery store. The items available in the grocery store are stored in the file named “inventory.txt.” Each item has an item number, an item name, taxability, a selling type and a unit price.

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
  #include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

const double itemTax = .06;

int writeFile(void)
{
	ofstream outFile;
	outFile.open("C:\\Users\\Stephen\\Documents\\Visual Studio 2013\\Projects\\Project10-7\\receipt.txt");

	outFile << fixed << setprecision(2) << "Here is your receipt! Thanks for shopping at Super Mart. " << endl;

	outFile << "Item Number " << setw(15) << " Item Name " << setw(7) << "Unit" << setw(7) << "Tax" << setw(15) << " Unit Price " << setw(15) << "Subtotal " << endl;

	outFile << "-------------------------------------------------------------------------------------------------------------------------------------" << endl;

	cout.setf(ios::left);

	outFile.close();
	return 0;
}

void checkout(void)
{
	int itemNumber, quanity, input,numberOf;
	char itemName[20], sellingType, itemTax;
	double unitPrice, subTotal, tax, preTotal, itemtax;
	double total;

	ifstream dataIN;

	dataIN.open("C:\\Users\\Stephen\\Documents\\Visual Studio 2013\\Projects\\Last one\\inventory.txt");

	{

		cerr << "Error:file could not be opened" << endl;

		exit(1);
	}

	do //Continuely ask the shopper for input till the input of 0 inputted.
	{
		cout << "Now, which item you would like to buy? ( Enter 0 to complete the transaction )" << endl;
		cin >> input;


		bool trigger = false;
		while (!dataIN.eof()){

			string dummyLine;
			getline(dataIN, dummyLine);
			dataIN >> itemNumber >> itemName >> itemTax >> sellingType >> unitPrice;


			if (itemNumber == input){
				trigger = true;

				//will determine what the user inputed will be based off as far as the cost of each buy, the tax of each item and the item type (pounds, units and single items)

				if (sellingType == 'p') {


					cout << "How many pounds would you like to buy?: " << endl;

					cin >> numberOf;
					while (numberOf < 0){
						cout << "How many pounds would you like to buy?: " << endl;

						cin >> numberOf;
					}

					preTotal = numberOf * unitPrice;

				}


				else if (sellingType == 'n')

				{
					cout << "How many units would you like to buy?: " << endl;

					cin >> numberOf;

					while (numberOf < 0){
						cout << "How many units would you like to buy?: " << endl;

						cin >> numberOf;
					}


					preTotal = numberOf * unitPrice;

				}

				else {

					numberOf = 1;

				}

				//Calculates the tax

				if (itemTax == 't') {

					preTotal = numberOf * unitPrice;

					itemtax = (itemTax)*(preTotal);

				}

				else{

					itemtax = 0.00;

				}
				//Calculate the total for entire purchase

				subTotal = preTotal + itemtax;

				total = total + subTotal;

			
					outfile << setw(8) << itemNumber << setw(20) << itemName << setw(7) << numberOf << setw(7) << itemtax << setw(15) << unitPrice << setw(15) << subTotal << endl;
				itemNumber = 0;
			}
		}
		if (!trigger && input != 0) {
			cout << "This is an invalid item. Please enter a valid item number." << endl;
		}
		dataIN.clear(); //clears the inputs when looping

		dataIN.seekg(0, ios::beg);

		} while (input != 0); // will exit the loop if the input is equal to zero

	outfile << "TOTAL " << setw(61) << "$" << total << endl;

}

int main()
{
	cout << " Welcome to Super Mart! " << endl;

	cout << " Item number " << setw(14) << "Item name " << setw(14) << " Unit price " << endl;

	cout << "----------------------------------------" << endl;

	cout << setw(13) << " 34" << setw(17) << "Vegatable_2" << setw(14) << "1.99 " << endl;

	cout << setw(13) << " 56" << setw(17) << "Coffee_A" << setw(14) << "5.99 " << endl;

	cout << setw(13) << " 78" << setw(17) << "Fruit_3" << setw(14) << "0.33 " << endl;

	cout << "----------------------------------------" << endl;

}
Last edited on
Topic archived. No new replies allowed.