Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<malloc.h>
- struct sual{
- int price;
- char customer[20];
- char dress[20];
- struct sual *next;
- };
- struct sual *start = NULL;
- void menu(){
- printf("BLUE DRESS SHOP CASHIER QUEUE\n");
- printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
- printf("1. view queue\n");
- printf("2. add customer to queue\n");
- printf("3. serve to customer\n");
- printf("4. exit\n");
- printf("input :");
- }
- struct sual *add(struct sual *start){
- struct sual *newsual,*ptr;
- int harga;
- char pembeli[20],pakaian[20];
- do{
- printf("input customer's [3...20]: " );
- scanf("%[^\n]",pembeli);
- getchar();
- }while (strlen(pembeli)<3 || strlen(pembeli)>20);
- do{
- printf("input dress's [3...20]: " );
- scanf("%[^\n]",pakaian);
- getchar();
- }while (strlen(pakaian)<3 || strlen(pakaian)>20);
- do {
- printf("input dress's price[$3...$999] : ");
- scanf("%d",&harga );
- } while(harga < 3 || harga > 999);
- newsual= (struct sual*)malloc(sizeof(struct sual));
- strcpy(newsual->customer,pembeli);
- strcpy(newsual->dress,pakaian);
- newsual -> price = harga;
- ptr=start;
- if (start == NULL) {
- newsual -> next = start;
- start = newsual;
- }else{
- newsual -> next = NULL;
- while(ptr -> next != NULL){
- ptr = ptr -> next; }
- ptr -> next = newsual;
- }
- return start;
- }
- struct sual *queue(struct sual *start) {
- struct sual *ptr;
- ptr = start;
- if(ptr == NULL){
- printf("\ntidak ada data...");
- }else{
- printf("| customer's name | dress's name | price($)\n\n");
- while (ptr != NULL){
- printf("| %-15s | %-15s | %-10d \t\n",ptr->customer,ptr->dress,ptr->price );
- ptr = ptr -> next;
- }
- }
- getchar();
- return start;
- }
- struct sual *sell(struct sual *start){
- struct sual *ptr;
- ptr = start;
- if (start == NULL) {
- printf("------------- NO Queue------------");
- }else if(start != NULL){
- printf("-------------- has been served -------------\n" );
- start = start -> next;
- free(ptr);
- }
- getchar();
- return start;
- }
- struct sual *example(struct sual *start){
- struct sual *kastemer1;
- kastemer1 = (struct sual *)malloc(sizeof(struct sual));
- start = kastemer1;
- strcpy(kastemer1->customer, "ali");
- strcpy(kastemer1->dress, "kaos golkar");
- kastemer1->price = 67;
- kastemer1->next = NULL;
- return start;
- }
- int main(){
- int pilih;
- start = example(start);
- do{
- system("cls");
- menu();
- scanf("%d",&pilih );
- getchar();
- if(pilih==1){
- start=queue(start);
- }else if(pilih==2){
- start=add(start);
- }else if(pilih==3){
- start=sell(start);
- }
- }while(pilih !=4);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement