While trying to incorporate an error check to an update list function, the problem is that the list doesn't update. If the updated stock number that you enter is not a number, or another item of stock already has that number then the user is asked to input another number.
When the user enters a successful number, the screen clears and the list is shown. The problem is that in the updated number does not appear in the list.
Code:
/UPDATE DETAILS OF ITEMS ON THE LIST
void update( int numitems)
{
// declare local variables
int i,j;
char tempstr[80];
char updatechoice[80];
do{
system ("cls");
listitems (numitems);
cout <<("\n\t\t ======UPDATE AN ITEM IN STOCK======\n\n");
cout << "\t\t 1. Update stock number\n";
cout << "\t\t 2. Update description\n";
cout << "\t\t 3. Update supplier\n";
cout << "\t\t 4. Update quantity\n";
cout << "\t\t 5. Update price\n";
cout << "\t\t Q. End update \n";
cout << "\n\t\t ================\n";
cout << "\n\t\t Press appropriate key to select > ";
cin >> updatechoice;
if (!strcmp(updatechoice, "1"))
{
cout <<("\nEnter stock number of item to be updated ... ");
cin >> tempstr;
j = atoi(tempstr);
cout <<"\nSearching for item number " << j;
for(i=0;i < numitems; i++)
if(j == slist[i].stocknumber)
{
cout <<"\nItem is: " ;
cout.width (6);
cout << slist[i].stocknumber ;
cout.width (25);
cout << slist[i].description ;
cout.width (25);
cout << slist[i].supplier ;
cout.width (4);
cout << slist[i].quantity ;
cout.width (10);
cout << slist[i].price ;
cout <<("\n\n\t\t Enter the stock number of the new item ");
} stockcheck:
cin >>tempstr;
if ((atoi(tempstr)) == 0)
{
cout << "\n not valid";
cout <<("\n\t\t Enter the stock number of the new item ");
goto stockcheck;
}
for(i=0; i < numitems; i++)
{
if((atoi(tempstr)) == (slist[i].stocknumber))
{
cout <<"\n\nnumber alredy exists";
cout <<("\n\t\t Enter the stock number of the new item ");
goto stockcheck;
}
}
slist[i].stocknumber = atoi(tempstr);
}