Borland C++ Help For Project

so this is my project(i actually have put 50 entries , but havent put them because of the word limit), and i have corrected all errors present in it , but it still doesnt seem to work! Whenever i run the program , it simply diaplys a 'thread stopped' message , and displays an empty window. Also , the line -
o = ((c[i].current-c[i].previous)/c[i].previous);
is highlited in blue. I am just a student and have learned c++ only for 3 months , so dont have much idea of it. Please do help me and tell me why this error occurs , and how i can correct it!




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
# include <iostream.h>
# include <conio.h>
# include <stdlib.h>
# include <stdio.h>
# include <dos.h>
# include <string.h>
struct stock{
char name[100];
char commodity[100];
float current;
float previous;
float change;
}c[50];



void select(stock c[]);
void categories(stock c[]);
void descending(stock c[]);

void main()
{
 strcpy(c[0].name,"Google");
strcpy(c[0].commodity,"Internet");
c[0].current=1085.35;
c[0].previous=1059.5;

strcpy(c[1].name,"Konami");
strcpy(c[1].commodity,"Games(ADR)");
c[1].current=24.38;
c[1].previous=24.28;

strcpy(c[2].name,"Yahoo");
strcpy(c[2].commodity,"Internet");
c[2].current=39.57;
c[2].previous=38.2;

strcpy(c[3].name,"Samsung");
strcpy(c[3].commodity,"Electronics");
c[3].current=1085.35;
c[3].previous=1,400.00;

strcpy(c[4].name,"Bank Of America");
strcpy(c[4].commodity,"Banking and Finance");
c[4].current=15.30;
c[4].previous=15.65;

strcpy(c[5].name,"Ford Motor");
strcpy(c[5].commodity,"Automobile");
c[5].current=16.42;
c[5].previous=16.7;

strcpy(c[6].name,"Nokia");
strcpy(c[6].commodity,"Electronics(ADR)");
c[6].current=17.86;
c[6].previous=17.80;

strcpy(c[7].name,"Coco Cola");
strcpy(c[7].commodity,"Consumer Product");
c[7].current=39.93;
c[7].previous=40.25;

strcpy(c[8].name,"Disney");
strcpy(c[8].commodity,"Consumer Product");
c[8].current=69.62;
c[8].previous=71.5;

strcpy(c[9].name,"Twitter");
strcpy(c[9].commodity,"Internet");
c[9].current=59.00;
c[9].previous=47.2;

strcpy(c[10].name,"PEPSI CO.");
strcpy(c[10].commodity,"Consumer Product");
c[10].current=80.93;
c[10].previous=82.4;

strcpy(c[11].name,"Toyota Motor Corporation");
strcpy(c[11].commodity,"Automobile(ADR)");
c[11].current=119.22;
c[11].previous=122.3;

strcpy(c[12].name,"Apple Inc.");
strcpy(c[12].commodity,"Electronics");
c[12].current=554.33;
c[12].previous=560.00;

strcpy(c[13].name,"Hewlett Packard");
strcpy(c[13].commodity,"Electronics");
c[13].current=26.77;
c[13].previous=27.5;

strcpy(c[14].name,"Intel Co-orporation");
strcpy(c[14].commodity,"Electronics");
c[14].current=1085.35;
c[14].previous=1059.5;

strcpy(c[15].name,"AMD");
strcpy(c[15].commodity,"Electronics");
c[15].current=3.69;
c[15].previous=3.69;

strcpy(c[16].name,"Aeropostale Inc");
strcpy(c[16].commodity,"Consumer Products");
c[16].current=8.15;
c[16].previous=9.0;

strcpy(c[17].name,"The Boeing Company");
strcpy(c[17].commodity,"Automobile");
c[17].current=133.83;
c[17].previous=130.1;

strcpy(c[18].name,"Canon INC");
strcpy(c[18].commodity,"Consumer Product");
c[18].current=31.65;
c[18].previous=29.85;

strcpy(c[19].name,"Colgate-Palmolive Company");
strcpy(c[19].commodity,"Consumer Product");
c[19].current=63.98;
c[19].previous=63.78;

strcpy(c[20].name,"Dolby Laboratories, Inc.");
strcpy(c[20].commodity,"Electronics");
c[20].current=37.00;
c[20].previous=35.98;


float o;
for(int i = 0; i<50;i++)
{
o = ((c[i].current-c[i].previous)/c[i].previous);
c[i].change = o;
}
cout <<"Kindly select what you would like to do :\t1 - Browse stocks of companies based on category\t2 - Search the current stock details of your desired company\t3 - See the list of companies based on descending order of increase in stocks\t";
cout << "Please enter the serial number of your desired operation : ";
int n;
cin >> n;
if (n==1)
categories(c);
if(n==2)
select(c);
if(n==3)
descending(c);
getch();
}

void select(stock c[50])
{
clrscr();
cout << "The list of companies are :\n1 - Google\n2 - Konami\n3 - Yahoo\n4 - Samsung\n5 - Bank Of America\n6 - Ford Motors\n7 - Nokia\n8 - Coco Cola\n9 - Disney\n10 - Twitter\n11 - PEPSI CO." ;
cout <<"Kindly give the serial number of the company whose stocks you\nto see : ";
int k;
cin >> k;
int f=(k-1);
cout <<"\nThe stock details of the required compaines are :\n " ;
cout <<"\nCompany name : " << c[f].name;
cout <<"\nCommodity Type : " <<c[f].commodity;
cout <<"\nCurrent stock price : " <<c[f].current;
cout <<"\nStock price 3 days back : " <<c[f].previous;
cout <<"\nChange in stocks in 3 days : " <<c[f].change<<"\n\n";
}

void categories(stock c[50])
{
clrscr();
int n;
cout <<"The categories that the companies belong to are :\n1 - Internet\n2 - Games\n3 - Electronics\n4 - Banking and Finance\n5 - Consumer Products\n6 - Automobile\n7 - ADR";
cout <<"Kindly enter the serial number of the category of which you would like\nto view stocks of :\n" ;
cout << "Serial number : ";
cin >> n;
for(int i=0 ; i<50 ; i++)
{
if (n==1)
{
if(strcmp(c[i].commodity,"Internet"))
{
cout << c[i].name <<"\n";
cout << "Current stock price : "<<c[i].current << "\n";
cout << "Change in stocks as compared to last week : "<<c[i].change<<"\n\n\n";
}
}
if (n==2)
{
if(strcmp(c[i].commodity,"Games"))
{
cout << c[i].name <<"\n";
cout << "Current stock price : "<<c[i].current << "\n";
cout << "Change in stocks as compared to last week : "<<c[i].change<<"\n\n\n";;
}
}
if (n==3)
{
if(strcmp(c[i].commodity,"Electronics"))
{
cout << c[i].name <<"\n";
cout << "Current stock price : "<<c[i].current << "\n";
cout << "Change in stocks as compared to last week : "<<c[i].change<<"\n\n\n";
}
}
if (n==4)
{
if(strcmp(c[i].commodity,"Banking and Finance"))
{
cout << c[i].name <<"\n";
cout << "Current stock price : "<<c[i].current << "\n";
cout << "Change in stocks as compared to last week : "<<c[i].change<<"\n\n\n";
}
}
if (n==5)
{
if(strcmp(c[i].commodity,"Consumer Product") )
{
cout << c[i].name <<"\n";
cout << "Current stock price : "<<c[i].current << "\n";
cout << "Change in stocks as compared to last week : "<<c[i].change<<"\n\n\n";
cout << "Current stock price : "<<c[i].current << "\n";
cout << "Change in stocks as compared to last week : "<<c[i].change<<"\n\n\n";
}
}
if (n==6)
{
if(strcmp(c[i].commodity,"Automobile"))
{
cout << c[i].name <<"\n";
cout << "Current stock price : "<<c[i].current << "\n";
cout << "Change in stocks as compared to last week : "<<c[i].change<<"\n\n\n";
}
}
}
if(n==7)
{
cout << c[1].name<<endl;
cout << "Current stock price : "<<c[1].current << "\n";
cout << "Change in stocks as compared to last week : "<<c[1].change<<"\n\n\n";
cout << c[6].name<<endl;
cout << "Current stock price : "<<c[6].current << "\n";
cout << "Change in stocks as compared to last week : "<<c[6].change<<"\n\n\n";
cout << c[11].name<<endl;
cout << "Current stock price : "<<c[11].current << "\n";
cout << "Change in stocks as compared to last week : "<<c[11].change<<"\n\n\n";
}
}
void descending(stock c[50])
{
cout << "The list of companies in decreasing order of weekly stock increases\nare: " ;
stock a[50];
float k;
a[50]=c[50];
for(int i=0;i<50;i++)
{
 for(int j = 0; j<50;j++)
 {
  if(a[j].change<a[j+1].change)
  {
   k = a[j].change;
   a[j]=a[j+1];
   a[j+1].change=k;
   }
  }
 }
 for (int i=0;i<50;i++)
 {
 cout << (i+1) << " ) " << "Name : " << a[i].name<<endl;
 cout <<"    "<< "Weekly Change : " <<a[i].change<<" %";
 }
 }

S
Most likely this line has a divide by zero error:
o = ((c[i].current-c[i].previous)/c[i].previous);
You could avoid this by testing the value to see whether it is valid before attempting to divide if (c[i].previous != 0)

The Borland compiler is rather antiquated and some of the code is not standard C++. The #includes should look like this in C++, notice there is no ".h" for the standard C++ versions.
1
2
3
4
5
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <conio.h> 

The code should also have main returning an int, not void, int main()
@ Chervil , well as i stated ive been learning c++ for only the previous 4-5 months , so i follow whatever is taught at school , and hence the ".h" and the "void" main :P .
Btw , thanks a TON . Your tip cleared up my issue , and it now runs exactly like i wanted it to :D.
Thanks a lot!
Topic archived. No new replies allowed.