home *** CD-ROM | disk | FTP | other *** search
/ Light / Light_Vol.1_July_1992_Datasphere_Publications_Disk_1_of_2_Side_B.d64 / functions.c < prev    next >
Text File  |  2023-02-26  |  2KB  |  125 lines

  1. /*
  2.  
  3.    Functions - Chapter 2
  4.  
  5. */
  6.  
  7. #include "h:stdio.h"
  8. #define clear_screen printf("\223");
  9.  
  10.  
  11. /* --- Display day of week from number --- */
  12.  
  13.  
  14. char *getname(f_day)
  15. int f_day;
  16. {SHIFT-+}
  17.  
  18. static char *day[] = {SHIFT-+} "day 0, hmmm....",
  19.                        "Monday",
  20.                        "Tuesday",
  21.                        "Wednesday",
  22.                        "Thursday",
  23.                        "Friday",
  24.                        "Saturday",
  25.                        "Sunday"       {SHIFT--};
  26.  
  27. return ((f_day <1 {CBM--}{CBM--} f_day>7)?day[0]:day[f_day]);
  28. {SHIFT--}
  29.  
  30.  
  31. /* --- display x to the power y --- */
  32.  
  33.  
  34. double power(x,y)
  35.  
  36. double x;
  37. int y;
  38.  
  39. {SHIFT-+}      if (y==0)
  40.            return 1;
  41.        if (y<0)
  42.            return 1/power(x,-y);
  43.        else
  44.            return x*power(x,y-1);
  45. {SHIFT--}
  46.  
  47.  
  48. /* --- work out new vat prices -- */
  49.  
  50.  
  51. float vat(amount)
  52. float amount;
  53.  
  54. {SHIFT-+}
  55.    float vat15;
  56.    float new;
  57.  
  58.    vat15 = (float)100/115*amount;
  59.  
  60.    printf("\n\nPrice less 15%% VAT : %f",vat15);
  61.  
  62.    new =  (float)117.5/115*amount;
  63.    return new;
  64.  
  65. {SHIFT--}
  66.  
  67.  
  68. main()
  69. {SHIFT-+}
  70.    char day_num;
  71.    double a;
  72.    int b;
  73.    float x,new_price;
  74.  
  75.    clear_screen;
  76.    printf("Function Example 1: Days");
  77.    printf("\n\nRelated function  : *getname(f_day)");
  78.  
  79.    printf("\n\nEnter a day number (1 to 7) : ");
  80.  
  81.    day_num=(getchar()-48);
  82.  
  83.    printf(" %s",getname(day_num));
  84.  
  85.    printf("\n\n\nPress a key...");
  86.    getchar();
  87.  
  88.    clear_screen;
  89.    printf("Function Example 2: Powers");
  90.    printf("\n\nRelated function  : double power(x,y)");
  91.    printf("\n\nThis function can be found in the Super-C manual");
  92.  
  93.    printf("\n\nEnter a value for x: ");
  94.    scanf("%lf",&a);
  95.  
  96.    printf("\nEnter a value for y: ");
  97.    scanf("%d",&b);
  98.  
  99.    printf("\n\n%.2lf to the power of %d equals %.2lf\n",a,b,power(a,b));
  100.  
  101.    printf("\n\n\nPress a key...");
  102.    getchar();
  103.  
  104.  
  105.    clear_screen;
  106.    printf("Function Example 3: VAT");
  107.    printf("\n\nRelated function  : float vat(amount)");
  108.  
  109.    printf("\n\nEnter price inc. VAT at 15%% : ");
  110.    scanf("%f",&x);
  111.  
  112.    new_price = vat(x);
  113.    printf("\n\nNew price with VAT at 17.5%% : %f",new_price);
  114.  
  115.    printf("\n\n\nPress a key...");
  116.    getchar();
  117.  
  118.    printf("\n\n\nHo...Hum...loading menu....");
  119.    exec("c-menu");
  120.  
  121.  
  122. {SHIFT--}
  123.  
  124.  
  125.  
  126.