Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.2 kB
1
Indexable
Never
#include<stdio.h>
#include<stdlib.h>
typedef struct singly_list
{
    int id;
    int quantity;
    int amt;
    struct singly_list *next;

}*SLL;
SLL getnode()
{
    SLL new1= NULL;
    new1 = malloc(sizeof(struct singly_list));
    if(new1 ==NULL)
    {
        printf("\n Memory not availble");
        exit(0);
    }
    new1->next =NULL;
    return new1;
}
int main()
{
    SLL head=NULL,new1,temp,temp1;
    char res,r;
     int max,min;
    int choice,daysale=0,dayq=0;
    int idmin=-1;
    int idmax=-1;
     do
    {
         if(head ==NULL)
         {
             head =getnode();
             printf("\n\tEnter id :\t");
             scanf("%d", &head->id);
             printf("\n\tEnter quantity :\t");
             scanf("%d", &head->quantity);
             head->amt=80*head->quantity;
             temp =head;
         }
         else
         {
             new1 = getnode();
             printf("\n\tEnter id :\t");
             scanf("%d", &new1->id);
             printf("\n\tEnter quantity :\t");
             scanf("%d", &new1->quantity);
             new1->amt=80*new1->quantity;
             temp->next = new1;
             temp = new1;
         }
         printf("\n\t\t\tWant to add more bills :\t");
         scanf(" %c", &res);
    }while(res =='y');
    do
    {
      printf("\n1:Display of sale of a day\n2:Maximum And Minimum sale\n");
      printf("Enter your choice:");
      scanf("%d",&choice);
      switch(choice)
      {
      case 1:
          printf("\tID\tQuantity\tAmount\n");
          temp =head;
                while(temp!=NULL)
                {
                    printf("\t%d\t%d\t\t%d\n",temp->id,temp->quantity,temp->amt);
                    temp =temp->next;
                }
            temp1=head;
                while(temp1!=NULL)
                {
                    dayq = dayq+temp1->quantity;
                    daysale=daysale+temp1->amt;
                    temp1 =temp1->next;
                }
                printf("\n\nSale of a  day :%d COFFEE of RS %d",dayq,daysale);
                        break;

        case 2:
              temp =head;
              max=head->amt;
              min=head->amt;
            while(temp!=NULL)
                {
                    if(temp->amt>max)
                    {
                        max=temp->amt;
                    }
                    if(temp->amt<max)
                    {
                        min=temp->amt;
                    }
                    temp =temp->next;
            }
            temp =head;
            while(temp!=NULL)
            {
                if(temp->amt==max)
                {
                    idmax=temp->id;
                }
                if(temp->amt==min)
                {
                    idmin=temp->id;
                }
                 temp =temp->next;
            }
            printf("Minimum :%d RS & id is %d\n",min,idmin);
            printf("Maximum :%d RS & id is %d\n",max,idmax);
            break;
      }
       printf("\n\t\t\tWant to Continue :\t");
         scanf(" %c", &r);
    }while(r=='y');
}