My program allows me to add as many items until you hit the max, when you when all it shows you all the information you have entered in. When you go to display one, when I search for the first spot in the array it pops up, but after I search the 4th or 5th item I entered in, it says it hasn't been found, but it's obviously there. Any help.
#include <stdio.h>
#include <stdlib.h>
#define MAX 12
//Structed Items
struct item{
char itemname[20];
char itemdes[30];
int itemID;
int itemOH;
double itemUP;
};
// Function Declarations
int getMenu_Choice ();
int process (int choice, int count, struct item inven[]);
int add (int count, struct item inven[]);
int showall(int count, struct item inven[]);
int find(int count, struct item inven[]);
int main (void)
{ // OPENS MAIN
// Declarations
int choice;
struct item inven[MAX];
int count = 0;
// Statements
do//
{
choice = getMenu_Choice ();
count = process (choice, count, inven);
}
while (choice != 0);
return 0;
} // CLOSE MAIN
/*============================getChoice=*/
int getMenu_Choice (void)
{ //OPEN GETCHOICE
// Declarations
int choice;
// Statements
printf("\n\n**********************************");
printf("\n MENU ");
printf("\n\t1.Create A New Item ");
printf("\n\t2.View All Items ");
printf("\n\t3.View One Item ");
printf("\n\t0.Exit ");
printf("\n**********************************");
printf("\nPlease Type Your Choice Using 0-3");
printf("\nThen Hit Enter: ");
scanf("%d", &choice);
return choice;
} //CLOSES GET CHOICE
/*============================process=*/
int process (int choice, int count, struct item inven[])
{// OPEN PROCESS
// Declarations
// Statements
switch(choice)
{
case 1: count = add(count, inven);
break;
case 2: showall(count, inven);
break;
case 3: find(count, inven);
break;
case 0: exit;
break;
deafult: printf("Sorry Option Not Offered");
break;
} // switch
return count;
} // CLOSE PROCESS
/*============================add one=*/
int add(int count, struct item inven[])
{//OPENS CREATE
// Declarations
int i;
i = count;
if (i < MAX)
{
printf("Enter the Item ID:\n");
scanf("%d", &inven[i].itemID);
printf("Enter the Item Name:\n");
scanf("%s", inven[i].itemname);
i++;
}
else {
printf("sorry there is no more room for you to add");
};
return i;
}; // CLOSE CREATE
/*============================showall=*/
int showall(int count, struct item inven[])
{
//Declarations
int i;
// Statements
for(i = 0; i < count; i++)
{
printf("\nItem ID : %d", inven[i].itemID);
printf("\nItem Name : %s", inven[i].itemname);
};
return 0;
};
/*============================find one=*/
int find(int count, struct item inven[])
{
//Declarations
int i;
int search;
int found;
printf("Enter the Item ID to search\n");
scanf("%d", &search);
for (i = 0; i < count; i++)
{
if(inven[i].itemID == search)
{
printf("\nItem ID : %d", inven[i].itemID);
printf("\nItem Name : %s", inven[i].itemname);
break;
}
else {
printf("\nSorry None existent");
break;
}
}
return 0;
};
;at the end of}is uneccessary. And why doesshowallandfindreturn anint? Why not make the return typevoid?exit;→exit(0);,deafult:→default: