#include<stdio.h>

typedef struct book
{
char titel[20];
char auther[20];
long int isbn;
char puplisher [20];
float price;
int quantity;
int flag;
}book;


void AddNewBook(book[] );
void DisplayTable(book [] );
int search_book(book [] ,int);
void changprice(book []);


void main()
{
	int x,e,num;
	
	book books[100];
	
	for(int i=0;i<100;i++)
		books[i].flag=0;

	do{
		printf("\n\n");
     printf("        ********************************************\n");
     printf("	*1-add newt*                               *\n");
     printf("	*2-display*                                *\n");
     printf("	*3-search*                                 *\n");
     printf("	*4-change price                            *\n");
     printf("	*5-exit*                                   *\n");
     printf("	********************************************\n");
     printf("Enter your choice:");
     scanf("%d",&x);
     
     switch(x){
     case 1:
	 AddNewBook(books);
     break;

     case 2:
	 DisplayTable( books);
     break;

     case 3:
		 printf("\n enter the ISBN\n");
      scanf("%d",&num);
	  e=search_book( books,num);
      if (e==-1)
     printf("the book not found");
     break;

     case 4:
     changprice( books);
     break;

   
    
	 case 5:
	 printf("\ngood bay\n");
	 break;
     }
   } while(x!=5);
  
}



void AddNewBook(book books[])
{
	for(int i=99;i>0;i--){
		if (books[i].flag==0)
			break;
		else continue;
	}

printf("enter the title of the new book:");
scanf("%s",books[i].titel);
printf("enter the auther of the book:");
scanf("%s",books[i].auther);
printf("enter the ISBN of the book");
scanf("%ld",&books[i].isbn);
printf("enter the puplisher of the book:");
scanf("%s",books[i].puplisher);
printf("enter the price of the book:");
scanf("%f",&books[i].price);
printf("enter the nomber of quantity of the book :");
scanf("%d",&books[i].quantity);

books[i].flag=1;
}

void DisplayTable(book books[])
{
	
printf("1) tit\t   2)auth\t   3)isbn\t   4)pupl\t   5)price\t   6)qua\n");
for (int i=99; books[i].flag!=0; i--)
{
printf("%s\t   %s\t\t%ld\t\t",books[i].titel,books[i].auther,books[i].isbn);
printf("%s\t\t%f\t   %d",books[i].puplisher,books[i].price,books[i].quantity);
}

}
int search_book(book books[],int x)
{
	int y;
int postion=-1;

for (y=99; y>books[y].flag!=0; y--){
	if (books[y].isbn==x){
    postion=y;
    break;
	}
}

return postion;
}

void changprice(book books[])
{
	int postion;
	long int z;
    float f;

printf("Enter the isbn of the book");
scanf("%ld",&z);

printf("enter the new price\n");
scanf("%f",&f);

postion=search_book(books,z);

books[postion].price=f;

}