C project

Please Help me . . .
I encounter a problem regarding my project in Basic Computer Programming.
We are not allowed to use complicated commands

#include<stdio.h>

box(int x, int y, int xx, int yy)

{
int a,b;

{a=x;b=y;
do{gotoxy(a,b);
putch(196);
a++;
}while(a<=xx);
}
{a=x;b=y;
do{gotoxy(a,b);
putch(179);
b++;
}while(b<=yy);
}
{a=xx;b=y;
do{gotoxy(a,b);
putch(179);
b++;
}while(b<=yy);
}
{a=x;b=yy;
do{gotoxy(a,b);
putch(196);
a++;
}while(a<=xx);
}
{gotoxy(x,y);
putch(218);}
{gotoxy(xx,yy);
putch(217);}
{gotoxy(x,yy);
putch(192);}
{gotoxy(xx,y);
putch(191);}
}

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;

m=21.50;n=6.00;o=35.45;p=55.60;q=32.25;r=15.00;s=24.50;
t=29.00;u=18.50;v=27.50;subtotal=0;salestax=0;tax=0.12;pay=0;

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");

box(1,10,32,14);
gotoxy(20,11);
printf("2.Shampoo");
gotoxy(19,12);
printf("Php 6.00/pc");

box(1,10,48,14);
gotoxy(36,11);
printf("3.Cologne");
gotoxy(35,12);
printf("Php 35.45/pc");

box(1,10,64,14);
gotoxy(52,11);
printf("4.Lotion");
gotoxy(51,12);
printf("Php 55.60/pc");

box(1,10,80,14);
gotoxy(66,11);
printf("5.Baby Powder");
gotoxy(67,12);
printf("Php 32.25/pc");

box(1,15,16,19);
gotoxy(3,16);
printf("6.Toothbrush");
gotoxy(3,17);
printf("Php 15.00/pc");

box(1,15,32,19);
gotoxy(18,16);
printf("7.Toothpaste");
gotoxy(18,17);
printf("Php 24.50/pc");

box(1,15,48,19);
gotoxy(35,16);
printf("8.Mouth Wash");
gotoxy(35,17);
printf("Php 29.00/pc");

box(1,15,64,19);
gotoxy(52,16);
printf("9.Tissue");
gotoxy(51,17);
printf("Php 18.50/pc");

box(1,15,80,19);
gotoxy(69,16);
printf("0.Alcohol");
gotoxy(67,17);
printf("Php 27.50/pc");

box(1,20,80,24);
}

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*/

case 'b':clrscr();
box(5,1,75,18);
gotoxy(10,2);
printf ("%6s%18s%18s%20s", "QTY", "DESCRIPTION", "UNIT PRICE","TOTAL PRICE");
gotoxy(10,3);
printf ("--------------------------------------------------------------");
gotoxy(10,4);
printf ("%6d %13s %16.2f %18.2f",c[ctr],"Soap",m,c[ctr]*m);
gotoxy(10,5);
printf ("%6d %13s %16.2f %18.2f",d[ctr],"Shampoo",n,d[ctr]*n);
gotoxy(10,6);
printf ("%6d %13s %16.2f %18.2f",e[ctr],"Cologne",o,e[ctr]*o);
gotoxy(10,7);
printf ("%6d %13s %16.2f %18.2f",f[ctr],"Lotion",p,f[ctr]*p);
gotoxy(10,8);
printf ("%6d %13s %16.2f %18.2f",g[ctr],"Baby Powder",q,g[ctr]*q);
gotoxy(10,9);
printf ("%6d %13s %16.2f %18.2f",h[ctr],"Toothbrush",r,h[ctr]*r);
gotoxy(10,10);
printf ("%6d %13s %16.2f %18.2f",i[ctr],"Toothpaste",s,i[ctr]*s);
gotoxy(10,11);
printf ("%6d %13s %16.2f %18.2f",j[ctr],"Mouth Wash",t,j[ctr]*t);
gotoxy(10,12);
printf ("%6d %13s %16.2f %18.2f",k[ctr],"Tissue",u,k[ctr]*u);
gotoxy(10,13);
printf ("%6d %13s %16.2f %18.2f",z[ctr],"Alcohol",v,z[ctr]*v); /*this is the part where i "printf" the z[ctr]*/
gotoxy(10,15);
subtotal=((c[ctr]*m)+(d[ctr]*n)+(e[ctr]*o)+(f[ctr]*p)+(g[ctr]*q)+(h[ctr]*r)+(i[ctr]*s)+(j[ctr]*t)+(k[ctr]*u)+(z[ctr]*v));
salestax=(subtotal*tax);
t1=(salestax+subtotal);
total[ctr]=t1;
printf(" SUBTOTAL: %10.2f",subtotal);
gotoxy(10,16);
printf(" TAX: %10.2f",salestax);
gotoxy(10,17);
printf(" TOTAL: %10.2f",total[ctr]);

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");

box(1,10,16,14);
gotoxy(6,11);
printf("1.Soap");
gotoxy(3,12);
printf("Php 21.50/pc");

box(1,10,32,14);
gotoxy(20,11);
printf("2.Shampoo");
gotoxy(19,12);
printf("Php 6.00/pc");

box(1,10,48,14);
gotoxy(36,11);
printf("3.Cologne");
gotoxy(35,12);
printf("Php 35.45/pc");

box(1,10,64,14);
gotoxy(52,11);
printf("4.Lotion");
gotoxy(51,12);
printf("Php 55.60/pc");

box(1,10,80,14);
gotoxy(66,11);
printf("5.Baby Powder");
gotoxy(67,12);
printf("Php 32.25/pc");

box(1,15,16,19);
gotoxy(3,16);
printf("6.Toothbrush");
gotoxy(3,17);
printf("Php 15.00/pc");

box(1,15,32,19);
gotoxy(18,16);
printf("7.Toothpaste");
gotoxy(18,17);
printf("Php 24.50/pc");

box(1,15,48,19);
gotoxy(35,16);
printf("8.Mouth Wash");
gotoxy(35,17);
printf("Php 29.00/pc");

box(1,15,64,19);
gotoxy(52,16);
printf("9.Tissue");
gotoxy(51,17);
printf("Php 18.50/pc");

box(1,15,80,19);
gotoxy(69,16);
printf("0.Alcohol");
gotoxy(67,17);
printf("Php 27.50/pc");

box(1,20,80,24);break;


}
}while (cmd!='x');
clrscr();
printf("%d",z[ctr]);

getch();
}

when i run it, the value of alcohol (z[ctr]) becomes 98, eventhough i declare it to be 0. What am I suppose to do . . . Please help me . . .
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    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.

This:
 
    scanf("%d",pay);

has the & missing, should be:
 
    scanf("%d",&pay);
Last edited on
Topic archived. No new replies allowed.