title: add quantity of value if that value exists in array fuction in C
body: <p>I'm having a problem with writing code that is used for payment for books.
  It have to add quantity if ISBN number is the same, but it doesn't add quantity and it makes another value that has same ISBN... I can't figure out how can I add quantity in the existing value. I think the problem is in the <code>searchinventory</code> function, or <code>addbook</code> itself.</p>
  
  <hr>
  
  <pre><code>#include &lt;stdio.h&gt;
  #define MAX_BOOKS 10
  #define MAX_TITLE_SIZE 20
  
  struct Book {
      int _isbn; //International Standard Book Number
      float _price; //Book Price
      int _year; // Publication Year
      char _title[MAX_TITLE_SIZE]; //Book Title
      int _qty; //Book Quantity
  };
  //////////////////////////////////
  void flushKeyboard(void);
  void displayInventory(const struct Book book[],const int size);
  void addBook(struct Book book[],int *size);
  int searchInventory(const struct Book book[],const int isbn,const int size);
  void checkPrice(const struct Book book[],const int size);
  ///////////////////////////////////
  void flushKeyboard(void)
  {
      char enter;
      do{
          scanf("%c",&amp;enter);
  
  
      }while(enter != '\n');
  }
  void displayInventory(const struct Book book[],const int size){
      int i = 0;
      printf("\n\nInventory\n");
      printf("===================================================\n");
      printf("ISBN      Title               Year Price  Quantity\n");
      printf("---------+-------------------+----+-------+--------\n");
  
      for(i=0;i&lt;size;i++){
              printf("%-10.0d%-20s%-5d$%-8.2f%-8d\n",book[i]._isbn,book[i]._title,book[i]._year,book[i]._price,book[i]._qty);
      }
      printf("===================================================\n\n");
  }
  //////////////////////////////////////////////
  void addBook(struct Book book[],int *size){
      int result = -1;
      int _isbn;
      int _qty;
  
      if(*size == MAX_BOOKS){
          printf("the inventory is full");
  
      }
  
      else{
          printf("ISBN:");
  
          scanf("%d",&amp;_isbn);
          result = searchInventory(&amp;book[*size],_isbn,*size);
  
          printf("_isbn = %d\n",_isbn);
          printf("Quantity:");
  
          scanf("%d",&amp;_qty);
  
          if(result != -1){
              book[result]._isbn = _isbn;
              book[result]._qty = book[result]._qty + _qty;
              printf("The book exists in the repository, quantity is updated.\n");
  
              printf("book[result]._qty is %d\n",book[result]._qty);
              printf("book[*size]._qty is %d\n",book[*size]._qty);
              }
          if(result == -1){
              book[*size]._isbn = _isbn;
              book[*size]._qty = _qty;
              printf("Title:");
  
              scanf(" %20[^\n]",book[*size]._title);
              flushKeyboard();
              printf("Year:");
              scanf("%d",&amp;book[*size]._year);
              printf("Price:");
              scanf("%f",&amp;book[*size]._price);
              printf("The book is successfully added to the inventory.\n\n");
  
          }
          }
  }
  //////////////////////////////////////////////////////////////////////////////
  int searchInventory(const struct Book book[],const int isbn,const int size){
      int i = 0;
      int result = -1;
      for(i=0;i&lt;size;i++){
          if(isbn == (book[i]._isbn)){
  
              result = i;
              return result;
              break;
          }
      }
  
      return result;
  }
  /////////////////////////////////////////////////////////////////////////////
  void checkPrice(const struct Book book[],const int size){
      int isbn;
      int i = 0;
  
      printf("Please input the ISBN number of the book\n\n");
      scanf("%d",&amp;isbn);
  
      i = searchInventory(&amp;book[size],isbn,size);
  
      printf("Book %d costs %.2d\n\n",isbn,book[size]._price);
  }
  int main(void){
  
      struct Book book[MAX_BOOKS];
      int size=0;
      int option;
      printf("Welcome to the Book Store\n=========================\n");
      do{
  
          printf("Please select from the following options:\n");
          printf("1) Display the inventory.\n");
          printf("2) Add a book to the inventory.\n");
          printf("3) Check price.\n");
          printf("0) Exit.\n");
  
          printf("\nSelect: ");
          scanf("%d",&amp;option);
          switch(option){
              case 1:
                  if(size == 0){
                      printf("The inventory is empty!\n");
                      printf("===================================================\n\n");
  
                  }
                  else{
                          displayInventory(book,size);
                  }
  
                  break;
              case 2:
              //SIZE++;
              addBook(book,&amp;size);
              size++;
                  break;
              case 3:
                  printf("Please select input the ISBN number of the book: \n\n");
                  //checkPrice();
                  break;
              case 0:
                  printf("Goodbye!\n");
                  break;
              default: //wrong input
                  printf("Invalid input, try again:\n");
                  break;
          }
      }while(option!=0);
  
  
      return 0;
  }
  </code></pre>