hello ninyo.
nag-lisod ko sa amo project sa skul.. naa koy 3 arrays.. i assign values to them using for loops and scanf. then the program asks if i want to add another value to the array.
it works for the first 2 or 3 increments to the array but after that, one of the values of the array is messed up.. please help.

here is the code, i added some comments to try and clarify it a bit:
Code:
#include<stdio.h>
#define TRUE 1
#define FALSE 0
int check(char ans,char big,char small){
if(ans == big || ans == small){
return TRUE;
}else{
return FALSE;
}
}
ADDITEM(){
/*initialize*/
int x,last,i;
printf("Enter # of items: ");
scanf("%d",&x);
int code[x], price[x];
char ans, name[x][30];
ans = 'y';
last = i = 0;
while(check(ans,'Y','y')){
/*ask for input*/
for(i = last;i < x;i++){
printf("Enter item code #%d: ",i+1);
scanf("%d",&code[i]);
printf("Enter name of item #%d: ",i+1);
scanf("%s",&name[i]);
printf("Enter item price #%d: ",i+1);
scanf("%d",&price[i]);
}
/*print list of values*/
printf("\n----------LIST-----------\n");
for (i = 0;i<x;i++){
printf("\nItem code #%d: %d",i+1,code[i]);
printf("\nItem name #%d: %s",i+1,name[i]);
printf("\nItem price #%d: %d",i+1,price[i]);
printf("\n");
}
last = x; /*assign last value of x to variable for reference*/
/*ask user to increment list*/
printf("\n\nAdd another item[Y/N]? ");
scanf("%s",&ans);
if(check(ans,'N','n')){
break;
}else if(check(ans,'Y','y')){
x++;
}else{
while(!check(ans,'N','n')||!check(ans,'Y','y')){
if(check(ans,'N','n')||check(ans,'Y','y')){
if(check(ans,'Y','y')){
x++;
}
break;
}else{
printf("Y or N?");
scanf("%s",&ans);
}
}
}
}
}
main(){
char choice;
choice = '\0';
printf("START [Y/N]? ");
scanf("%s", &choice);
while(!check(choice,'n','N')){
if(check(choice,'Y','y')){
ADDITEM();
}else if(check(choice,'n','N')){
break;
}
}
}