main()
{
int c[20],d[20],e[20],f[20],g[20],h[20],i[20],j[20],k[20],z[20];
int cmd,ctr,q1,q2,q3,q4,q5,q6,q7,q8,q9,q0,t1;
float m,n,o,p,q,r,s,t,u,v,subtotal,total[20],salestax,tax,pay;
ctr=0;
while (ctr<20)
{c[ctr]=0;
d[ctr]=0;
e[ctr]=0;
f[ctr]=0;
g[ctr]=0;
h[ctr]=0;
i[ctr]=0;
j[ctr]=0;
k[ctr]=0;
z[ctr]=0; /*this is the part where i declare the value of z to be zero*/
total[ctr]=0;
ctr++;
}
textbackground (03);
textcolor(04);
clrscr();
{
box(26,1,56,3);
gotoxy(32,2);
printf("PANGZ' MINI-MARKET");
box(1,5,80,9);
gotoxy(10,6);
printf("Please Press the ASSIGNED NUMBER to Input the No. of Pcs. Needed");
gotoxy(34,7);
printf("Press 'b' to buy");
gotoxy(20,8);
printf("Press the Password to Access Inventory");
}
{
box(1,10,16,14);
gotoxy(6,11);
printf("1.Soap");
gotoxy(3,12);
printf("Php 21.50/pc");
do{
cmd=getch();
switch (cmd)
{
case '1':
gotoxy(8,13);
scanf("%d",&q0);
c[ctr]=q0;
break;
case '2':
gotoxy(24,13);
scanf("%d",&q1);
d[ctr]=q1;break;
case '3':
gotoxy(40,13);
scanf("%d",&q2);
e[ctr]=q2;break;
case '4':
gotoxy(56,13);
scanf("%d",&q3);
f[ctr]=q3;break;
case '5':
gotoxy(72,13);
scanf("%d",&q4);
g[ctr]=q4;break;
case '6':
gotoxy(8,18);
scanf("%d",&q5);
h[ctr]=q5;break;
case '7':
gotoxy(24,18);
scanf("%d",&q6);
i[ctr]=q6;break;
case '8':
gotoxy(40,18);
scanf("%d",&q7);
j[ctr]=q7;break;
case '9':
gotoxy(56,18);
scanf("%d",&q8);
k[ctr]=q8;break;
case '0':
gotoxy(72,18);
scanf("%d",&q9);
z[ctr]=q9;break; /*this is the part where I scan the value of z*/
box(10,20,70,24);
gotoxy(24,21);
printf("Enter the Amount You Will Pay");
scanf("%d",pay);
gotoxy(26,22);
printf("Press'g' to Go back to Menu");
gotoxy(22,23);
printf("Enter the Password to Access Inventory");
break;
case 'g':ctr++;
clrscr();
box(26,1,56,3);
gotoxy(32,2);
printf("PANGZ' MINI-MARKET");
box(1,5,80,9);
gotoxy(10,6);
printf("Please Press the ASSIGNED NUMBER to Input the No. of Pcs. Needed");
gotoxy(34,7);
printf("Press 'b' to buy");
gotoxy(26,8);
printf("Press 'i' to Access Inventory");
ctr=0;
while (ctr<20)
{
c[ctr]=0;
d[ctr]=0;
e[ctr]=0;
f[ctr]=0;
g[ctr]=0;
h[ctr]=0;
i[ctr]=0;
j[ctr]=0;
k[ctr]=0;
z[ctr]=0; /*this is the part where i declare the value of z to be zero*/
total[ctr]=0;
ctr++;
}
When this loop finishes, the value of ctr is 20
Permitted values are 0 to 19. ctr is never assigned a suitable value from this point onwards, so all access to the array uses elements outside the array bounds. Results are unpredictable.