Search This Blog

Friday, October 7, 2011

Illustration of nested if else

   1:  #include<stdio.h>
   2:  #include<conio.h>
   3:  void main()
   4:  {
   5:  int demand,stock;
   6:  char option;
   7:  printf("Enter the available stock:");
   8:  scanf("%d",&stock);
   9:  printf("Enter the demand:");
  10:  scanf("%d",&demand);
  11:  if(demand>stock)
  12:  {
  13:  printf("Maximum stock at hand %d\n",stock);
  14:  printf("Do you want to purchase type y:\n");
  15:  scanf("\n%c",&option);
  16:  if(option=='y' || option=='Y')
  17:  stock=0;
  18:  }
  19:  else
  20:  stock=stock-demand;
  21:  printf("Closing stock= %d\n",stock);
  22:  getch();
  23:  }

No comments:

Post a Comment