Pageviews last month

Tuesday, 20 December 2011

My New Baby of C Programming...
//Dream Cruise Holiday Company
//To calculate total cost for each customers
#include <stdio.h>
#include <conio.h>

int selection();
void showMenu();

int main(void)
{
  int command, cost=0, meal;

  showMenu();
  do{
      cost+=selection();
      printf("Any other order, Sir.\nYES>>1 NO>>0\n>>");
      scanf("%d",&command);
     }while(command==1);

  printf("Do you want to purchase meal vouchars, sir?\n");
  printf("Enter amounts of meal vouchers>> RM");
  scanf("%d",&meal);

  cost+=meal;
  printf("\nTotal of this transaction is RM%d.", cost);
  printf("\n\nThank You For Purchasing Our Service.");
  printf("\nHave a nice day...");

  getch();
  return 0;
}

void showMenu()
{
  printf("Dream Cruise Holiday Company\nPrice List>>\n\n");
  printf("Normal Price>>\nAdult:RM200 Child:RM140\nOrder Code: 1\n\n");
  printf("Family Package>>\n2 Adults and 2 children only.\nAt only RM600.\nOrder Code: 2\n\n");
  printf("Group Travel Package>>\n10 people whose travel together\nCost only RM1800 (save
             RM200).\nOrder Code: 3\n\n");
}

int selection()
{
  int nA, nC, nFP, nGP, order_code, cost;

  do{
      printf("Please enter your order code>>");
      scanf("%d",&order_code);

      switch(order_code)
      {
        case 1: printf("Enter the no. of adult>>");
                scanf("%d", &nA);
                printf("Enter the no. of child>>");
                scanf("%d",&nC);
                cost=(nA*200)+(nC*140);
                break;

        case 2: printf("Enter the no. of family package>>");
                scanf("%d",&nFP);
                cost=nFP*600;
                break;

        case 3: printf("Enter the no of group package>>");
                scanf("%d",&nGP);
                cost=nGP*1800;
                break;

        default: printf("You have entered an invalid code, please try again.\n");
      }
    }while(order_code>3);

  return cost;
}

No comments:

Post a Comment