Topic : C++ for Dumies
Author : Randy Nixon
Page : << Previous 3  
Go to page :

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.


In this chapter we are going to do a simple for loop. It's really quite simple, and it's not as hard as some might think. Well kiddies, let's begin;
#include < stdio.h >
main ( )
int i;
for (i=0; i<100; i++){
printf ("Oh digitalscribe your so fine, your so\n");
printf ("fine you blow my mind hey diggy, hey diggy\n");
return (0);

Well here we have some stuff that on the surface may seem a little deep but really it's not. Almost everything in the preceding block of code should be obvious, except for line 5 and 8 and whats in between. Let's look at line 5 shall we?

for (i=0; i<100; i++){

The for keyword is the what sets up the loop. Everything between the parenthesis (the argument) is what sets up the parameters of the loop. Above this line of code you see that an int variable was set up. In the for loop we have (and I realize I'm being redundant) set the parameters of that variable. Let's look deeper and explain the argument.


Here we have set the i variable to 0. This is the initialazation of what will be a "sort of" counter.


Here we have set the condition of the loop. This says that the loop will cycle as long as i is "less than" 100. As soon as i is equal to 100 than the argument is not less than 100 and it will stop. I guess you realize that I'm using the word argument a lot. It's basically programming talk for parameter.


This increments(makes it move up one digit). It tells i to basically continually move up

Anyways to put in pseudo code;

for (start count at 0; set it go 99 times; make i go){

Now that we have explained all that lets see how that little snippit of code relates to whats between the for brackets ({ }). Let us employ our abstract thinking shall we? Now this is just an analogy of sorts, don't take it literally. NOT ALL ANALOGIES ARE PERFECT!!!!!

Imagine that i is a aerobics instuctor. It goes into a gym and sees the front desk. The insturctor has no idea what his class is or what he's kind of excersie routine that he is supposed to lead his students through. The office coordinator (for) holds what the excersise routine is supposed to be. He is supposed to lead his students into 99 straight repititons of calestenics. So he goes into the gym (in the case whats between the for brackets) and starting with zero he goes through the routine 99 times and stops. In our case the 2 printf statements will be done 99 times and will stop.

Whew!!! That was a mouthful!!

A note on the incrementing thing. If you wanna use it to decrement you would use i--. However don't use it on what we just wrote....that would be screwey hehehe. Anyways I'll write some more stuff on loops later, I'm getting tired. -Randimus

Page : << Previous 3