Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************************************
- *
- * tourCompany.c
- * Programming Project 1
- *
- * This program
- *
- * Created by Sitthiphong Achavan (Tum) ID 55070503474
- *
- * 00 November 2012
- *
- ***************************************************************
- */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- #define MAX 20
- /* this function will print the summary when reach to the end of the day (user enter END in firstName) */
- void printSummery(int discountCount,int haveDiscount,int noneDiscountCount,int tour1Count,int tour2Count,int tour3Count,int tour4Count)
- {
- printf("DUMP\n");
- printf("DUMP\n");
- printf("DUMP\n");
- printf("DUMP\n");
- printf("DUMP\n");
- }
- /* this function will print a bills for each customers */
- void printBill(char* firstName,char* discountCode,char date[][11],int* tourType,int* tourCustomer,int haveDiscount,int tourCount)
- {
- int i;
- double finalTotal=0;
- double total=0;
- double discount=0;
- double tourPrice=0;
- char tourTypeDisplay[5][32] = {"","Temple Tour","Floating Market","Bang Pa-in","Sukhothai"};
- printf ("Customer Bill\n");
- printf ("Member Name : %s\n",firstName);
- printf ("Discount Code : %s\n",discountCode);
- for (i=0;i<=tourCount;i++)
- {
- tourCount -= 1;
- printf("Tour Date : %s\n",date[i]);
- printf("Tour Name : %s\n",tourTypeDisplay[tourType[i]]);
- printf("Number of Customer : %d\n",tourCustomer[i]);
- switch (tourType[i])
- {
- case 1:
- tourPrice = 700;
- break;
- case 2:
- tourPrice = 900;
- break;
- case 3:
- tourPrice = 1100;
- break;
- case 4:
- tourPrice = 2500;
- break;
- total += tourPrice;
- }
- printf("Total price before discount : %lf\n",total);
- if ((haveDiscount = 1) && ((tourCustomer[i] >= 0)||(tourCustomer[i] <= 3)))
- {
- discount = total*(13/100);
- }
- printf("Discount : %lf\n",discount);
- finalTotal = total - discount;
- printf("Total price after discount : %lf\n",finalTotal);
- }
- }
- /* this function will check the discount code from customer that discount code is valid or not*/
- int checkDiscountCode(char* discountCode)
- {
- int i=0; /* count which character in discountCode is currently working in*/
- int j=0; /* count which character in discountCode is currently working in*/
- if (((strlen(discountCode)) > 6) || ((strlen(discountCode)) < 6))
- {
- if (strcmp(discountCode,"0") == 0)
- {
- return 1; /*this customer don't have a discount code*/
- }
- else
- {
- return 0; /*discount code shouldn't be longer than 6 chars or less than 6*/
- }
- }
- else
- {
- for (j=1;j<=3;j++)
- {
- if ((isdigit(discountCode[j])) == 1)
- {
- for (i=4;i<=6;i++)
- {
- if ((isalpha(discountCode[i])) != 3)
- {
- return 2; /*discount code is correct*/
- }
- else
- {
- return 0; /*discount code after 3 numbers shouldn't with 3 number or other*/
- }
- }
- }
- else
- {
- return 0; /*discount code shouldn't begin with 3 alphabet or other*/
- }
- }
- }
- }
- void calculateBook()
- {
- }
- int main()
- {
- char input[32];
- char firstName[32];
- char discountCode[7];
- int discountCount=0;
- int noneDiscountCount=0;
- int haveDiscount;
- int customerNumber=0;
- int customerCount=0;
- int tourNumber;
- int tourCount=0;
- char date[MAX][11];
- int tourType[MAX];
- int tourCustomer[MAX];
- int tour1Count;
- int tour2Count;
- int tour3Count;
- int tour4Count;
- for (customerNumber=0;customerNumber<=customerCount;customerNumber++)
- {
- printf("Enter your First name or END if it's end of the day\n");
- fgets(input,32,stdin);
- sscanf(input,"%s",firstName);
- if ((strcmp(firstName,"END")) == 0)
- {
- printSummery(discountCount,haveDiscount,noneDiscountCount,tour1Count,tour2Count,tour3Count,tour4Count);
- exit(0);
- }
- else
- {
- printf("Enter your discount code (3 digits then 3 letters or 0 if you don't have any discount code\n");
- fgets(input,32,stdin);
- sscanf(input,"%s",discountCode);
- while (checkDiscountCode(discountCode)==0)
- {
- printf("Error,Please enter the valid Discount Code\n");
- fgets(input,32,stdin);
- sscanf(input,"%s",discountCode);
- }
- if (checkDiscountCode(discountCode)==1)
- {
- haveDiscount=0;
- noneDiscountCount =+ 1;
- }
- if (checkDiscountCode(discountCode)==2)
- {
- haveDiscount=1;
- discountCount += 1;
- }
- customerCount += 1;
- tourCount = 0;
- for (tourNumber=0;tourNumber<=tourCount;tourNumber++)
- {
- printf("Member name : %s\n",firstName);
- printf("Discount Code : %s\n",discountCode);
- printf("Order : %d\n",tourCount);
- printf("Enter your date of tours (date should be DD/MM/YYYY)\n");
- fgets(input,32,stdin);
- sscanf(input,"%s",date[tourNumber]);
- if ((strcmp(date[tourNumber],"00")) == 0)
- {
- printBill(firstName,discountCode,date,tourType,tourCustomer,haveDiscount,tourCount);
- }
- else if ((strcmp(date[tourNumber],"00")) != 0)
- {
- while (((strlen(date[tourNumber])) > 10) || ((strlen(date[tourNumber])) < 10))
- {
- printf("Error,Please enter the valid date of tours\n");
- fgets(input,32,stdin);
- sscanf(input,"%s",date[tourNumber]);
- if ((strcmp(date[tourNumber],"00")) == 0)
- {
- printBill(firstName,discountCode,date,tourType,tourCustomer,haveDiscount,tourCount);
- }
- }
- }
- if (strlen(date[tourNumber]) == 10)
- {
- printf("Which tour do you want to book\n");
- printf("1.Temple Tour (700 baht/person)\n");
- printf("2.Floating Market (900 baht/person)\n");
- printf("3.Bang Pa-in (1100 baht/person)\n");
- printf("4.Sukhothai (2500 baht/person)\n");
- fgets(input,32,stdin);
- sscanf(input,"%d",&tourType[tourNumber]);
- if (tourType[tourNumber] = 1)
- {
- tour1Count += 1;
- }
- else if (tourType[tourNumber] = 2)
- {
- tour2Count += 1;
- }
- else if (tourType[tourNumber] = 3)
- {
- tour3Count += 1;
- }
- else if (tourType[tourNumber] = 4)
- {
- tour4Count += 1;
- }
- while ((tourType[tourNumber] < 1) || (tourType[tourNumber] > 4))
- {
- printf("Which tour do you want to book\n");
- printf("1.Temple Tou (700 baht/person)\n");
- printf("2.Floating Market (900 baht/person)\n");
- printf("3.Bang Pa-in (1100 baht/person)\n");
- printf("4.Sukhothai (2500 baht/person)\n");
- fgets(input,32,stdin);
- sscanf(input,"%d",&tourType[tourNumber]);
- if (tourType[tourNumber] = 1)
- {
- tour1Count += 1;
- }
- else if (tourType[tourNumber] = 2)
- {
- tour2Count += 1;
- }
- else if (tourType[tourNumber] = 3)
- {
- tour3Count += 1;
- }
- else if (tourType[tourNumber] = 4)
- {
- tour4Count += 1;
- }
- }
- tourCount += 1;
- printf("How many people?\n");
- fgets(input,32,stdin);
- sscanf(input,"%d",&tourCustomer[tourNumber]);
- while (tourCustomer[tourNumber] < 1)
- {
- printf("How many people?\n");
- fgets(input,32,stdin);
- sscanf(input,"%d",&tourCustomer[tourNumber]);
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment