what is the actual error in this code??i cant run it, plizz help me by teach me how to solve it

what is the actual error in this code?? plizz help me

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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
//***************************************************************
//                   HEADER FILE USED IN PROJECT
//****************************************************************

#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<fstream>
#include<ctype.h>
#include<windows.h>
using namespace std;

        void gotoxy(int x, int y)
        {
HANDLE hConsoleOutput;
COORD dwCursorPosition;
cout.flush();
dwCursorPosition.X = x;
dwCursorPosition.Y = y;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}
    void clrscr()
{
system("cls");
}
//***************************************************************
//                   CLASS USED IN PROJECT
//****************************************************************

class inventory
{
 int ivno;
 char name[50];
 int added, substract;
 float price;
 int quantity;
 public:
	void new_product()
	{
	 cout<<"\nEnter The Product No.";
	 cin>>ivno;
	 cout<<"\n\nEnter The Product Name ";
	 cin>>name;
	 cout<<"\nEnter The Quantity of Product ";
	 cin>>quantity;
	 cout<<"\nEnter the Product price";
	 cin>>price;
	 cout<<"\n\n\nProduct Log Created..";
         }

	void show_product()
	{
	 cout<<"\Product No. : "<<ivno;
	 cout<<"\nProduct Name : ";
	 puts(name);
	 cout<<"\nQuantity of product : "<<quantity;
	 cout<<"\nPrice of product : "<<price;
	 }


void add(int x)
{
  quantity+=x;
}

void subs(int x)
{
  quantity-=x;
}

void report()
{cout<<ivno<<"\t"<<name<<"\t\t"<<quantity<<"\t\t"<<price<<endl;}

  int  retivno()
  {return ivno;}

  float retprice()
  {return price;}

  int retquantity()
  {return quantity;}

  int retadd()
  {return add;}


};         //class ends here



//***************************************************************
//    	global declaration for stream object, object
//****************************************************************

 fstream fp;
 inventory iv;


//***************************************************************
//    	function to write in file
//****************************************************************

void add_product()
   {
    fp.open("inventory.dat",ios::out|ios::app);
    iv.new_product();
    fp.write((char*)&iv,sizeof(inventory));
    fp.close();
   }



//***************************************************************
//    	function to read specific record from file
//****************************************************************


void display_sp(int n)
{
    clrscr();
    cout<<"\nPRODUCT DETAILS\n";
    int flag=0;
    fp.open("INVENTORY.dat",ios::in);
    while(fp.read((char*)&iv,sizeof(inventory)))
	{
	 if(iv.retivno()==n)
		{
		 iv.show_product();
		 flag=1;
		}
	}
    fp.close();
if(flag==0)
 cout<<"\n\nSorry ,product number does not exist";
    getch();
}

//***************************************************************
//    	function to delete record of file
//****************************************************************


void delete_product()
   {
    int no;
    clrscr();
    cout<<"\n\n\n\tDelete Record";
    cout<<"\n\nEnter The product no. That You Want To Delete";
    cin>>no;
    fp.open("inventory.dat",ios::in|ios::out);
    fstream fp2;
    fp2.open("Temp.dat",ios::out);
    fp.seekg(0,ios::beg);
    while(fp.read((char*)&iv,sizeof(inventory)))
	{
	 if(iv.retivno()!=no)
		{
		 fp2.write((char*)&iv,sizeof(inventory));
		 }
	 }
    fp2.close();
    fp.close();
    remove("inventory.dat");
    rename("Temp.dat","inventory.dat");
    cout<<"\n\n\tRecord Deleted ..";
    getch();
    }


//***************************************************************
//    	function to display all accounts deposit list
//****************************************************************

    void display_all()
    {
     clrscr();
     fp.open("inventory.dat",ios::in);
     if(!fp)
     {
       cout<<"ERROR!!! FILE COULD NOT BE OPEN\n\n\n Go To Admin Menu to create File";
       getch();
       return;
     }

     cout<<"\n\n\t\tPRODUCTS LIST\n\n";
	  cout<<"====================================================\n";
	  cout<<"PRODUCT no.\tNAME\t\tQUANTITY\t\tPRICE\t\tSUM\n";
	  cout<<"====================================================\n";

      while(fp.read((char*)&iv,sizeof(inventory)))
	 {
	   iv.report();
	}
     fp.close();
}


//***************************************************************
//    	function to deposit and withdraw amounts
//****************************************************************

void add_substract(int option)
{
    int no,found=0,vle;
    clrscr();
    cout<<"\n\n\tEnter The inventory No.";
    cin>>no;
    fp.open("inventory.dat",ios::in|ios::out);
    while(fp.read((char*)&iv,sizeof(inventory)) && found==0)
       {
	    if(iv.retivno()==no)
	   {
		    iv.show_product();
		    if(option==1)
		       {
			cout<<"\n\n\tTO ADD ITEM ";
			cout<<"\n\nEnter The quantity to be added";
			cin>>vle;
			iv.add(vle);
		       }
		     if(option==2)
		       {
			cout<<"\n\n\tTO SUBSTRACT ITEM";
			cout<<"\n\nEnter The quantity to be substract";
			cin>>vle;
			 int bal=iv.retadd()-vle;
			 if(bal<0)
			      cout<<"Insufficience balance";
				   else
			       iv.subs(vle);
		      }
			 int pos=-1*sizeof(iv);
			 fp.seekp(pos,ios::cur);
			 fp.write((char*)&iv,sizeof(inventory));
			 cout<<"\n\n\t Record Updated";
			 found=1;
	       }
         }
    fp.close();
    if(found==0)
    cout<<"\n\n Record Not Found ";
    getch();
}





//***************************************************************
//    	INTRODUCTION FUNCTION
//****************************************************************

void intro()
{
 clrscr();
 gotoxy(31,11);
 cout<<"SHOP";
 gotoxy(35,14);
 cout<<"INVENTORY";
 gotoxy(39,17);
 cout<<"RECORD SYSTEM";
 getch();

}



//***************************************************************
//    	THE MAIN FUNCTION OF PROGRAM
//****************************************************************


int main()
{
  char ch;
  intro();
  do
    {
	  clrscr();
	  cout<<"\n\n\n\tMAIN MENU";
	  cout<<"\n\n\t01. ADD NEW PRODUCT";
	  cout<<"\n\n\t02. ADD PRODUCT QUANTITY";
	  cout<<"\n\n\t03. SUBTRACT PRODUCT QUANTITY";
	  cout<<"\n\n\t04. DISPLAY ALL PRODUCT LIST";
	  cout<<"\n\n\t05. DELETE A PRODUCT";
	  cout<<"\n\n\t06. EXIT PROGRAM";
	  cout<<"\n\n\tSelect Your Option (1-6) ";
	  ch=getche();
	  switch(ch)
	  {
		case '1': clrscr();
			  add_product();
			  getch();
			break;
		case '2': clrscr();
			  quantity(1);
			  break;
		case '3': clrscr();
			  quantity(2);
			  getch();
          		  break;
		case '4': clrscr();
			  display_all();
			getch();
			 break;
		case '5': delete_product();
			  break;

		  case '6':exit(0);
		  default :cout<<"\a";
	}
    }while(ch!='6');
}



You need to tell use what error message you are getting. We are not mind readers, and at least I am not the regular 20 questions gamer. Does this compile? If not, show the error. If it does compile, then what's wrong with it? You must DEFINE what wrong is, and you also MUST define what right is so an expert can properly provide help.
this is the error..

: In member function 'void inventory::show_product()':
:55: warning: unknown escape sequence: '\P' [enabled by default]

: In member function 'int inventory::retadd()':
:86: error: argument of type 'void (inventory::)(int)' does not match 'int'

In function 'int main()':
:298: error: 'quantity' was not declared in this scope
1. The warning is saying that you are probably missing something in line 55. I guess the correct string is "\nProduct" instead of "\Product"?
2. You are returning the address of the function named "add" in line 86, which is definitely not an int, and the return type of the function (line 85) states that the return must be of type int.
3. I don't see a declaration of the variable named 'quantity' in the code, do you? If you see it, let me know which line. Note that the one in line #38 doesn't count because it is private to the class and therefore inaccessible from outside the class (such as main()).
ok, thankz webJose..!!
You cannot do this way .. unless it is structure .

(fp.read((char*)&iv,sizeof(inventory))

many function are defined global when you can define it in the class . this is not a proper design of the class .please design the class again .
Topic archived. No new replies allowed.