I cleaned it up a little, added some basic screen functions, "clrscr()" and "system("PAUSE")", and introduced the "continue" and "break" loop commands. My point is to show you there is an easier way than using all of those "hard-coded" variables.
i hope it helps.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.c>
int main()
{
int idpur [4];
int sold; // <--now just one variable
printf("Please enter the initial number of cases of Coca-Cola: \n");
scanf("%d", &idpur [0]);
printf("Please enter the initial number of cases of Pepsi: \n");
scanf("%d", &idpur [1]);
printf("Please enter the initial number of cases of Dr. Pepper: \n");
scanf("%d", &idpur [2]);
printf("Please enter the initial number of cases of Canada Dry: \n");
scanf("%d", &idpur [3]);
while(1) // <--INFINITE LOOP
{
printf("Please enter the ID number: \n");
printf("1 = Coca-Cola\n");
printf("2 = Pepsi\n");
printf("3 = Dr. Pepper\n");
printf("4 = Canada Dry\n");
printf("0 = Quit\n");
scanf("%d", &id );
if( id == 0 )
break; // <-- break out of while loop, print totals
else if( id > 4 )
{
printf("You have entered ann invalid code!\n");
continue; // <-- Go back to the top of while loop
}
i = id - 1; //<-- set "i" to proper array element
printf("Please enter the qunatity to sell: \n");
scanf("%d", &sold );
if( sold > idpur[i] ) //<-- i is equiv to coresponding array element
{
printf("Not sold! There are only %d cases available.\n", idpur [i]);
}
else
{
idpur[i] = idpur[i] - sold; // or...// idpur[i] -= sold;
printf("%d cases are sold and %d cases are left.\n", sold, idpur[i]);
}
system("PAUSE"); //<-- you need this to pause screen
clrscr(); //<-- you need this to clear the screen
} //<-- End of infinite loop
clrscr();
printf("Final Counts: \n");
printf("Coca-Cola: %d\n", idpur[0]);
printf("Pepsi: %d\n", idpur[1]);
printf("Sr. Pepper: %d\n", idpur[2]);
printf("Canada Dry: %d\n", idpur[3]);
system("PAUSE");
return 0;
}