Thread: C Newbie Hitting Trouble

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    3

    C Newbie Hitting Trouble

    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!

    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: Also, the donation amount[don_amt] for each type becomes a huge number =/. The 3rd option is deliberately missing; skipped it.
    Edit: Initial problem resolved; will keep open in case I hit a new issue with the program, thanks!
    Last edited by kevin13; 10-16-2012 at 06:39 PM. Reason: Add. Information

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie function trouble
    By Swerve in forum C++ Programming
    Replies: 6
    Last Post: 03-04-2008, 04:33 AM
  2. Newbie- having trouble with functions
    By bnmwad in forum C Programming
    Replies: 7
    Last Post: 02-22-2005, 04:41 PM
  3. anjuta [newbie] trouble
    By darksaidin in forum Linux Programming
    Replies: 20
    Last Post: 12-22-2003, 05:22 PM
  4. Replies: 1
    Last Post: 09-15-2002, 04:56 AM
  5. Newbie with trouble
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 10-19-2001, 08:04 PM

Tags for this Thread