EVEN MORE C TO BRIGHTEN YOUR DAY!!!

Welcome to the next little diddy on char. Sorry it takes soooo long between tutorials now. I've been real busy lately and it takes me a while to complete these. Anyways eventhough I promised it before but I will do my best to have a new tutorial up every week. Anyways come back every satuday and check out new updates.

If you recall last time we went into a little tidbit on char. There is much more we can learn from char variables and we will start this marvelous learning process by typing code. Enter this into your compilers and run it!

#include < stdio.h >
#include < conio.h >
main ( )
{
char key;
printf ("Enter a key!\n");
key = getche( );
printf ("\tYou pressed the '%c' key!!!", key);
return (0);
}

This is basically some of the same stuff we've done before and only it containes the getche function. It produces the same kind of effect as getch, only it displays immeadiately what you type. To help you distinguish between the two imagine that e at the end of getche stands for echo. Wait a minute! I wonder if it really does stand for echo? Hmmmmm........

I know in the last tutorial I said I would cover putchar ( ), but I think I'll hold off on that until we get into loops. I do that because the programs I use to discuss loops uses putchar a lot...that and the fact that I'm extremely lazy. Anyways we let us now discuss constants. Don't worry if the discussion on variable seem a bit scanty, as I go into further tutorials variables will also be used a lot and discussed plentifly.

BEHOLD CONSTANTS IN ALL IT'S MIGHTY GLORY!!!

Constants are extremely easy to comprehend. It almost works like variables in that the computer sets aside memory for values, but it is different in that these values are defined and set in stone. These values will not change. They refuse to compromise. They are not human. They cannot feel pain. They cannot be reasoned with............sorry. Type this into thy compiler and run it

#include < stdio.h >
#define TAX 10000000
main ( )
{
float x,t;
printf ("How old are you\n");
scanf ("%f",&x);
t = x*TAX;
printf ("You have insulted the mighty IRS you owe %.0f dollars!", t);
return (0);
}

We've done this type of program before. The only real difference is the #define TAX thingee and the placeholder %.0f.

#define TAX 10000000

So here you are creating a constant called "tax." You assigned a value to that constant 10000000. This will stay "constant." This will not change. You will not assimilate it. It will resist. It isn't hum...bleah sorry. Anyways it's going to stay the same.

printf ("You have insulted the mighty IRS you owe %.0f dollars!", t);

Remember a long ways back when I said I would tell you how to get rid of the decimals in float? Well there you go. By placing a 0 in behind the decimal point you are telling the computer to ignore everything next to the decimal. If you wrote a %.2f it would take it out to two decimal points.

Anyways, I'm sleepy so that will be all for now. Please come back next week and check out some more "neato" stuff with C.

BACK