how do I 'find' and 'delete' texts from a text file??

i have this assignment to submit tomorrow(friday) and i am having difficulties updating my text files. actually, i have to be able to update the text files by searching and deleting items. please, check the code below.. so far, i am receiving no errors except that the calculation part gives me different figures whenever it is run.... i need help soon.

ps: i am trying to create a text file to store information of a store that sells computers.


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
                   #include <iostream.h>
#include <conio.h>
#include <cstring.h>
#include <stdio.h>
#include <fstream.h>
 class products{
 public:
 string prodname;
 string prodName[25];
int noOfItem;
int priceOfItem[25];
int cprice[25];
int proProfit, sumcprice, sumpriceOfItem;//variables to calculate profit
//string x, inp1;
//defines the main menu/ main page
int mainMenu() {
//sets width and height of texts...
gotoxy(24,3);
	cout<<"\xDB\xDB\xDB\xDB\xB2  SAMMY COMPUTERS  \xB2\xDB\xDB\xDB\xDB";
	gotoxy(3,4);
	cout<<"--------------------------------------------------------------------------";
	gotoxy(35,5);
	cout<<("MAIN MENU");
	gotoxy(26,8);
	cout<<" 1  -   INFORMATION ABOUT PRODUCTS            ";
	gotoxy(26,10);
	cout<<" 2  -   ENTER PRODUCTS FOR SALE           ";
	gotoxy(26,12);
	cout<<" 3  -   VIEW INFO ON SALES PROFITS AND REPORTS";
	gotoxy(26,14);
	cout<<" 4  -   HELP                                  ";
	gotoxy(26,15);
	cout<<" 0  -   EXIT                                  ";
	//validates items on main menu
	return menuVal();
	}
int menuVal() {//validates the mainMenu() function
int inp;
cout<< "\n\n";
 cout<< "\nENTER YOUR CHOICE \n";
 cin>> inp;
switch(inp) {
case 1:
display();
break;

case 2:
setPro();
break;

case 3:
profitRep();
break;

case 4:
cout<< "displays help tips and more";
break;

case 0:
exit(0);
break;

default: {
//clrscr();
cout<< "WRONG INPUT, TRY AGAIN, PRESS ANY KEY TO RETURN TO MENU";
clrscr();
getche();
mainMenu();
break;}

}
return 0;
}
int display() {
char ch;
clrscr();
ifstream compstore;
compstore.open("sammycomps1.txt");
if(!compstore)
  {
  cout<<"UNABLE TO OPEN FILE!!";
  goto end;
  }
while(compstore)
	  {
	  compstore.get(ch);
	  cout<<ch;

	  }
getch();
end:
compstore.close();
cout<< "PRESS ANY KEY TO RETURN TO MAIN MENU";
getche();
clrscr();
return mainMenu();

}
int setPro(){
//remove after first input of data... use ios::app
cout<< "TO QUIT THE INPUT PROCESS DURING LOOP, ENTER '9' AND HIT THE RETURN KEY.";
for (int i=0; i<4; i++){
cout<< "ENTER DESCRIPTION. MUST BE TEN(10) CHARACTERS LONG\n";
cin>> prodname;
prodName[i]=prodname;
cout<< "ENTER ID NUMBER \n";
cin>> noOfItem;
cout<< "PRICE \n";
cin>> priceOfItem[i];
cout<< "COST PRICE \n" ;
cin>> cprice[i];
if ((prodname[i] == '9')||(noOfItem == '9')||(priceOfItem[i] == '9') ||(cprice[i] == '9')){
return mainMenu();
}
else{
ofstream compstore("sammycomps1.txt", ios::app); //create a file for output..
//COMMENT NEXT TWO LINES TO APPEND NEW DATA.
compstore<< "\n\n";
//compstore<< "    ---------------------------------------------------------------------" << endl<<endl ;
compstore<< prodName[i]<< "     ";
compstore<< noOfItem<< "     ";
compstore<< priceOfItem[i]<< "     ";
compstore<< cprice[i] << endl;
compstore.close();
}
 }
cout<<"ENTER ANY KEY TO RETURN TO MAIN MENU";
getche();
clrscr();
return mainMenu();
}
int profitRep() {
proProfit=0;
for (int x=0; x<2; x++){
cout<< priceOfItem[x] << "     "<< cprice[x]<< endl;
sumpriceOfItem = ((sumpriceOfItem) + (priceOfItem[x]));
sumcprice = ((sumcprice) + (cprice[x])) ;
}
proProfit= ((sumpriceOfItem)-(sumcprice));
cout<< "Total profit is : $"<< proProfit << endl;
cout<< "PRESS ANY KEY TO RETURN TO MENU ";
getche();
clrscr();
return mainMenu();
}
};
int main() {
products inventory;
inventory.mainMenu() ;
//inventory.menuVal() ;
return 0;
}

Topic archived. No new replies allowed.