Hey, more on said program, I want to remove requests/donations as they are fulfilled/depleted. I plan to run a for loop as so:
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int i, j, x, index, ch, found, don_quant, don_amt[100], don_count, req_amt[100], req_count, req_quant;
char word [20], don_inv_type[100][20], req_inv_type[100][20];
don_count = 0;
req_count = 0;
printf(" 1. Add a Donation \n 2. Add a request \n 3. Fulfull a request \n 4. Print status \n 5. Exit \n");
scanf("%d", &ch);
while(ch !=5){
if(ch == 1){
printf("Enter inventory type: ");
scanf("%s", word);
printf("Enter amount: ");
scanf("%d", &don_quant);
found = -99;
for(i=0; i<don_count; i++){
if(strcmp(don_inv_type[i], word) == 0)
found = i;
}
if(found == -99){
strcpy(don_inv_type[i], word);
don_amt[i] = don_quant;
don_count++;
}
else
don_amt[found] += don_quant;
}
else if(ch == 2){
printf("Enter inventory type: ");
scanf("%s", word);
printf("Enter amount: ");
scanf("%d", &req_quant);
strcpy(req_inv_type[req_count], word);
req_amt[req_count] = req_quant;
req_count++;
}
else if(ch ==3){
found = -99;
for(index=0; index<don_count; index++){
if(strcmp(don_inv_type[index], req_inv_type[0]) == 0)
found = index;
}
if(found==-99)
printf("\n-----Request Cannot Be Fulfilled-----\n");
else if(don_amt[found] > req_amt[0]){
don_amt[found]-=req_amt[0];
printf("\n-----Request Fulfilled-----\n");
req_amt[0]=0;
for (x=found; x<don_count; x++)
strcpy(don_inv_type[x], don_inv_type[x+1]);
don_inv_type[don_count] = 0;
don_count--;
}
else if(don_amt[found]==req_amt[0]){
don_amt[found]-=req_amt[0];
printf("\n-----Request Fulfilled-----\n");
req_amt[0]=0;
for (x=found; x<don_count; x++)
strcpy(don_inv_type[x], don_inv_type[x+1]);
don_inv_type[don_count] = 0;
don_count--;
for (x=0; x<req_count; x++)
strcpy(req_inv_type[x], req_inv_type[x+1]);
req_inv_type[req_count] = 0;
req_count--;
}
else{
req_amt[0]-=don_amt[found];
printf("\n-----Request Partially Fulfilled-----\n");
don_amt[found]=0;
for (x=0; x<req_count; x++)
strcpy(req_inv_type[x], req_inv_type[x+1]);
req_inv_type[req_count] = 0;
req_count--;
}
}
else if(ch == 4){
printf("\nPrinting Donation table: \n \n");
for(i=0; i<don_count; i++)
printf("%s %d \n", don_inv_type[i], don_amt[i]);
printf("\nPrinting Request table: \n \n");
for(i=0; i<req_count; i++)
printf("%s %d \n", req_inv_type[i], req_amt[i]);
}
printf("\n 1. Add a Donation \n 2. Add a request \n 3. Fulfull a request \n 4. Print status \n 5. Exit \n");
scanf("%d", &ch);
}
printf("\n\nThank You For Using This Program.\nHave A Nice Day!\n");
system("PAUSE");
return 0;
}
I am not certain if I'm on the right track, and, if I am, how do I remove the last row in each array, rather than having the last row a repeat of the one before it? Thank you again Click_Here, and to anyone else who can offer any advice =).
P.S. Checked and everything besides the red is working as I was going for.
Edit: Aware that the amounts haven't been bumped; stopped before I wrote that code to make sure there weren't two issues happening at the same time.