Guest User

Untitled

a guest
Dec 13th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.71 KB | None | 0 0
  1. /**************************************************************
  2. *  
  3. * tourCompany.c
  4. * Programming Project 1
  5. *
  6. *   This program
  7. *
  8. *   Created by Sitthiphong Achavan (Tum)  ID 55070503474
  9. *              
  10. *     00 November 2012
  11. *
  12. ***************************************************************
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <ctype.h>
  19. #define MAX 20
  20.  
  21. /* this function will print the summary when reach to the end of the day (user enter END in firstName) */
  22. void printSummery(int discountCount,int haveDiscount,int noneDiscountCount,int tour1Count,int tour2Count,int tour3Count,int tour4Count)
  23.     {  
  24.         printf("DUMP\n");
  25.         printf("DUMP\n");
  26.         printf("DUMP\n");
  27.         printf("DUMP\n");
  28.         printf("DUMP\n");
  29.     }
  30.  
  31. /* this function will print a bills for each customers */
  32. void printBill(char* firstName,char* discountCode,char date[][11],int* tourType,int* tourCustomer,int haveDiscount,int tourCount)
  33.     {
  34.     int i;
  35.     double finalTotal=0;
  36.     double total=0;
  37.     double discount=0;
  38.     double tourPrice=0;
  39.     char tourTypeDisplay[5][32] = {"","Temple Tour","Floating Market","Bang Pa-in","Sukhothai"};
  40.     printf ("Customer Bill\n");
  41.     printf ("Member Name : %s\n",firstName);
  42.     printf ("Discount Code : %s\n",discountCode);
  43.  
  44.     for (i=0;i<=tourCount;i++)
  45.         {
  46.         tourCount -= 1;
  47.         printf("Tour Date : %s\n",date[i]);
  48.         printf("Tour Name : %s\n",tourTypeDisplay[tourType[i]]);
  49.         printf("Number of Customer : %d\n",tourCustomer[i]);
  50.  
  51.         switch (tourType[i])
  52.             {
  53.             case 1:
  54.                 tourPrice = 700;
  55.                 break;
  56.             case 2:
  57.                 tourPrice = 900;
  58.                 break;
  59.             case 3:
  60.                 tourPrice = 1100;
  61.                 break;
  62.             case 4:
  63.                 tourPrice = 2500;
  64.                 break;
  65.         total += tourPrice;
  66.             }
  67.         printf("Total price before discount : %lf\n",total);
  68.         if ((haveDiscount = 1) && ((tourCustomer[i] >= 0)||(tourCustomer[i] <= 3)))
  69.             {
  70.             discount = total*(13/100);
  71.             }
  72.         printf("Discount : %lf\n",discount);
  73.         finalTotal = total - discount;
  74.         printf("Total price after discount : %lf\n",finalTotal);
  75.         }
  76.     }
  77.  
  78. /* this function will check the discount code from customer that discount code is valid or not*/
  79. int checkDiscountCode(char* discountCode)
  80.     {
  81.     int i=0; /* count which character in discountCode is currently working in*/
  82.     int j=0; /* count which character in discountCode is currently working in*/
  83.     if (((strlen(discountCode)) > 6) || ((strlen(discountCode)) < 6))
  84.         {
  85.         if (strcmp(discountCode,"0") == 0)
  86.             {
  87.             return 1; /*this customer don't have a discount code*/
  88.             }
  89.         else
  90.             {
  91.             return 0; /*discount code shouldn't be longer than 6 chars or less than 6*/
  92.             }
  93.         }
  94.     else
  95.         {
  96.         for (j=1;j<=3;j++)
  97.             {
  98.             if ((isdigit(discountCode[j])) == 1)
  99.                 {
  100.                 for (i=4;i<=6;i++)
  101.                     {
  102.                     if ((isalpha(discountCode[i])) != 3)
  103.                         {
  104.                         return 2; /*discount code is correct*/
  105.                         }
  106.                     else
  107.                         {
  108.                         return 0; /*discount code after 3 numbers shouldn't with 3 number or other*/
  109.                         }
  110.                     }
  111.                 }
  112.             else
  113.                 {
  114.                 return 0; /*discount code shouldn't begin with 3 alphabet or other*/
  115.                 }
  116.             }
  117.         }
  118.     }
  119.  
  120. void calculateBook()
  121.     {
  122.     }
  123.  
  124. int main()
  125.     {
  126.     char input[32];
  127.     char firstName[32];
  128.     char discountCode[7];
  129.     int discountCount=0;
  130.     int noneDiscountCount=0;
  131.     int haveDiscount;
  132.     int customerNumber=0;
  133.     int customerCount=0;
  134.     int tourNumber;
  135.     int tourCount=0;
  136.     char date[MAX][11];
  137.     int tourType[MAX];
  138.     int tourCustomer[MAX];
  139.     int tour1Count;
  140.     int tour2Count;
  141.     int tour3Count;
  142.     int tour4Count;
  143.    
  144.     for (customerNumber=0;customerNumber<=customerCount;customerNumber++)
  145.         {
  146.         printf("Enter your First name or END if it's end of the day\n");
  147.         fgets(input,32,stdin);
  148.         sscanf(input,"%s",firstName);
  149.  
  150.         if ((strcmp(firstName,"END")) == 0)
  151.             {
  152.             printSummery(discountCount,haveDiscount,noneDiscountCount,tour1Count,tour2Count,tour3Count,tour4Count);
  153.             exit(0);
  154.             }
  155.         else
  156.             {
  157.             printf("Enter your discount code (3 digits then 3 letters or 0 if you don't have any discount code\n");
  158.             fgets(input,32,stdin);
  159.             sscanf(input,"%s",discountCode);
  160.            
  161.             while (checkDiscountCode(discountCode)==0)
  162.                 {
  163.                 printf("Error,Please enter the valid Discount Code\n");
  164.                 fgets(input,32,stdin);
  165.                 sscanf(input,"%s",discountCode);
  166.                 }
  167.             if (checkDiscountCode(discountCode)==1)
  168.                 {
  169.                 haveDiscount=0;
  170.                 noneDiscountCount =+ 1;
  171.                 }
  172.             if (checkDiscountCode(discountCode)==2)
  173.                 {
  174.                 haveDiscount=1;
  175.                 discountCount += 1;
  176.                 }
  177.  
  178.             customerCount += 1;
  179.             tourCount = 0;
  180.  
  181.             for (tourNumber=0;tourNumber<=tourCount;tourNumber++)
  182.                 {
  183.                 printf("Member name : %s\n",firstName);
  184.                 printf("Discount Code : %s\n",discountCode);
  185.                 printf("Order : %d\n",tourCount);
  186.                 printf("Enter your date of tours (date should be DD/MM/YYYY)\n");
  187.                 fgets(input,32,stdin);
  188.                 sscanf(input,"%s",date[tourNumber]);
  189.  
  190.                 if ((strcmp(date[tourNumber],"00")) == 0)
  191.                     {
  192.                     printBill(firstName,discountCode,date,tourType,tourCustomer,haveDiscount,tourCount);
  193.                     }
  194.                 else if ((strcmp(date[tourNumber],"00")) != 0)
  195.                     {
  196.                     while (((strlen(date[tourNumber])) > 10) || ((strlen(date[tourNumber])) < 10))
  197.                         {
  198.                         printf("Error,Please enter the valid date of tours\n");
  199.                         fgets(input,32,stdin);
  200.                         sscanf(input,"%s",date[tourNumber]);
  201.  
  202.                         if ((strcmp(date[tourNumber],"00")) == 0)
  203.                             {
  204.                             printBill(firstName,discountCode,date,tourType,tourCustomer,haveDiscount,tourCount);
  205.                             }
  206.                         }
  207.                     }
  208.                 if (strlen(date[tourNumber]) == 10)
  209.                     {
  210.                     printf("Which tour do you want to book\n");
  211.                     printf("1.Temple Tour (700 baht/person)\n");
  212.                     printf("2.Floating Market (900 baht/person)\n");
  213.                     printf("3.Bang Pa-in (1100 baht/person)\n");
  214.                     printf("4.Sukhothai (2500 baht/person)\n");
  215.                     fgets(input,32,stdin);
  216.                     sscanf(input,"%d",&tourType[tourNumber]);
  217.                     if (tourType[tourNumber] = 1)
  218.                         {
  219.                         tour1Count += 1;
  220.                         }
  221.                     else if (tourType[tourNumber] = 2)
  222.                         {
  223.                         tour2Count += 1;
  224.                         }
  225.                     else if (tourType[tourNumber] = 3)
  226.                         {
  227.                         tour3Count += 1;
  228.                         }
  229.                     else if (tourType[tourNumber] = 4)
  230.                         {
  231.                         tour4Count += 1;
  232.                         }
  233.  
  234.                     while ((tourType[tourNumber] < 1) || (tourType[tourNumber] > 4))
  235.                         {
  236.                         printf("Which tour do you want to book\n");
  237.                         printf("1.Temple Tou (700 baht/person)\n");
  238.                         printf("2.Floating Market (900 baht/person)\n");
  239.                         printf("3.Bang Pa-in (1100 baht/person)\n");
  240.                         printf("4.Sukhothai (2500 baht/person)\n");
  241.                         fgets(input,32,stdin);
  242.                         sscanf(input,"%d",&tourType[tourNumber]);  
  243.                         if (tourType[tourNumber] = 1)
  244.                             {
  245.                             tour1Count += 1;
  246.                             }
  247.                         else if (tourType[tourNumber] = 2)
  248.                             {
  249.                             tour2Count += 1;
  250.                             }
  251.                         else if (tourType[tourNumber] = 3)
  252.                             {
  253.                             tour3Count += 1;
  254.                             }
  255.                         else if (tourType[tourNumber] = 4)
  256.                             {
  257.                             tour4Count += 1;
  258.                             }
  259.                         }
  260.                     tourCount += 1;
  261.                     printf("How many people?\n");
  262.                     fgets(input,32,stdin);
  263.                     sscanf(input,"%d",&tourCustomer[tourNumber]);
  264.  
  265.                     while (tourCustomer[tourNumber] < 1)
  266.                         {
  267.                         printf("How many people?\n");
  268.                         fgets(input,32,stdin);
  269.                         sscanf(input,"%d",&tourCustomer[tourNumber]);
  270.                         }
  271.                     }
  272.                 }
  273.             }
  274.         }
  275.     }
Add Comment
Please, Sign In to add comment