Exsiss |
10-08-2007 10:53 PM |
Help with simple loop program in C
New problem:Okay I now need to do the same program as below but without using continue. I have no idea how I am supposed to do this, so can someone lead me in the right direction? Thanks!
Old post: I'm having a bit of trouble with the following program I am supposed to make:
Quote:
Write a program to print out a simple counter for odd numbers between 0 and 9, inclusive, using a for loop and a continue statement. The for loop must use a postfix increment of the loop variable (counter++). Add a brief comment at the beginning of the file describing what the program does.
The program output should look like:
counter = 1
counter = 3
counter = 5
counter = 7
counter = 9
|
The script I have for it is:
Quote:
int main ( )
{
int counter;
for (counter=1; counter < 10; counter++)
{
if (counter == 2 || counter == 4 || counter == 6 || counter == 8);
continue;
printf(" counter = %d\n", counter);
}
return(0);
}
|
When I compile it in Shell it does not come up with any warnings, but when I try to run it, nothing happens. I've tried changing things around, but no matter what I do, nothing happens when I run the program. Any suggestions? Thanks!
P.S. I'm a beginner at C so if you can keep the programming lingo to a way I can understand it, that would be great!
|