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 >
Wrap
Text File
|
2023-02-26
|
2KB
|
125 lines
/*
Functions - Chapter 2
*/
#include "h:stdio.h"
#define clear_screen printf("\223");
/* --- Display day of week from number --- */
char *getname(f_day)
int f_day;
{SHIFT-+}
static char *day[] = {SHIFT-+} "day 0, hmmm....",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday" {SHIFT--};
return ((f_day <1 {CBM--}{CBM--} f_day>7)?day[0]:day[f_day]);
{SHIFT--}
/* --- display x to the power y --- */
double power(x,y)
double x;
int y;
{SHIFT-+} if (y==0)
return 1;
if (y<0)
return 1/power(x,-y);
else
return x*power(x,y-1);
{SHIFT--}
/* --- work out new vat prices -- */
float vat(amount)
float amount;
{SHIFT-+}
float vat15;
float new;
vat15 = (float)100/115*amount;
printf("\n\nPrice less 15%% VAT : %f",vat15);
new = (float)117.5/115*amount;
return new;
{SHIFT--}
main()
{SHIFT-+}
char day_num;
double a;
int b;
float x,new_price;
clear_screen;
printf("Function Example 1: Days");
printf("\n\nRelated function : *getname(f_day)");
printf("\n\nEnter a day number (1 to 7) : ");
day_num=(getchar()-48);
printf(" %s",getname(day_num));
printf("\n\n\nPress a key...");
getchar();
clear_screen;
printf("Function Example 2: Powers");
printf("\n\nRelated function : double power(x,y)");
printf("\n\nThis function can be found in the Super-C manual");
printf("\n\nEnter a value for x: ");
scanf("%lf",&a);
printf("\nEnter a value for y: ");
scanf("%d",&b);
printf("\n\n%.2lf to the power of %d equals %.2lf\n",a,b,power(a,b));
printf("\n\n\nPress a key...");
getchar();
clear_screen;
printf("Function Example 3: VAT");
printf("\n\nRelated function : float vat(amount)");
printf("\n\nEnter price inc. VAT at 15%% : ");
scanf("%f",&x);
new_price = vat(x);
printf("\n\nNew price with VAT at 17.5%% : %f",new_price);
printf("\n\n\nPress a key...");
getchar();
printf("\n\n\nHo...Hum...loading menu....");
exec("c-menu");
{SHIFT--}