Hey, I am trying to make a program about a food bank that can record donations, record requests, fulfill requests[permitted the donations have enough to], and show current donations/unfulfilled requests. I can't seem to have the requests be added without crashing. Any help is appreciated =D!
Edit: Also, the donation amount[don_amt] for each type becomes a huge number =/. The 3rd option is deliberately missing; skipped it.Code:#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int i, j, 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 == 4){
printf("Printing Donation table: \n \n");
for(i=0; i<don_count; i++)
printf("%s %d \n", don_inv_type[i], don_amt[i]);
printf("Printing Request table: \n \n");
for(i=0; i<req_count; i++)
printf("%s %d \n", req_inv_type[i], req_amt[i]);
}
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);
}
system("PAUSE");
return 0;
}
Edit: Initial problem resolved; will keep open in case I hit a new issue with the program, thanks!