Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- //int jumlah=0;
- void clear()
- {
- for(int i=0;i<25;i++)
- {
- printf("\n");
- }
- }
- struct data
- {
- char name[21];
- char type[100];
- int quantity;
- int price;
- struct data *next;
- }*head=NULL,*tail=NULL,*curr=NULL;
- void pushTail(char name[],char type[],int quantity,int price)
- {
- curr=(struct data*)malloc(sizeof(struct data));
- strcpy(curr->name,name);
- strcpy(curr->type,type);
- curr->quantity=quantity;
- curr->price=price;
- curr->next=NULL;
- if(head == NULL)
- {
- head=tail=curr;
- }
- else
- {
- tail->next=curr;
- tail=curr;
- }
- tail->next=NULL;
- }
- void itemlist()
- {
- clear();
- int i=1;
- printf("=============================================================================\n");
- printf("%5s. | %-20s | %-20s | %-10s | %-10s |\n","No.","Name","Type","Quantity","Price");
- printf("=============================================================================\n");
- curr=head;//posisi curr di head
- while(curr != head)
- {
- printf("%5d. | %-20s | %-20s | %-10d | %-10d |\n",i,curr->name,curr->type,curr->quantity,curr->price);
- curr=curr->next;
- i++;
- }
- printf("=============================================================================\n");
- getchar();
- }
- void additem(char name[],char type[],int quantity, int price)
- {
- char *tempname[21];
- char *temptype[100];
- int *tempqty;
- int *tempprice;
- do{
- printf("Input name fo the new item[3..20] = ");
- scanf("%[^\n]",&tempname);fflush(stdin);
- }while(strlen(*tempname)<3 || strlen(*tempname)>20);
- strcpy(name,*tempname);
- do{
- printf("input type of the new item[processor/graphic card/memory] = ");
- scanf("%[^\n]",temptype);fflush(stdin);
- }while(strcmp(*temptype,"processor")==1 ||strcmp(*temptype,"graphic card")==1 || strcmp(*temptype,"memory")==1);
- strcpy(type,*temptype);
- do{
- printf("input Quantity of the new item[1..20] = ");
- scanf("%[^\n]",*tempqty);fflush(stdin);
- }while(*tempqty<1 || *tempqty>20);
- quantity=*tempqty;
- do{
- printf("input Price of the new item[1..$1000] = $");
- scanf("%[^\n]",tempprice);fflush(stdin);
- }while(*tempprice<1 || *tempprice>1000);
- price=*tempprice;
- clear();
- printf("--- add new item success ---");
- }
- void menu()
- {
- clear();
- puts("BLUE COMPUTER ADMINISTRATOR");
- puts("+++++++++++++++++++++++++++");
- puts("1. Item List");
- puts("2. Add (PUSH) New Item");
- puts("3. Exit");
- printf(">> Input your choice : ");
- }
- int main()
- {
- int choose;
- do{
- choose=0;
- menu();
- scanf("%d",&choose);fflush(stdin);
- switch(choose)
- {
- case 1:itemlist();break;
- case 2:additem();break;
- }
- }while(choose !=3);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement