I am seriously stuck. I'm supposed to write a program that counts by 3's using a for loop with the increment clause either being 1 = i + 3 or i + = 3. So far this is what i have, but it's not even close to working. While it does not tell me that I have errors until the execution, once it runs i get a runtime error and must abort the program. Am I over thinking this? And how do you get the table (\t) function to work with the column headings and contents? This is so confusing! I've reread my book Deitel's C How to Program and looked up as much as I can on the web to find out more information on how to use it, but the book is vague with no examples, and the explanations that I found on the internet were very convoluted .

Your program is far more complicated than it needs to be. You already have the answer to the problem in your description. The iterator in your for loop should be i += 3 rather than i++ to use the loop to count by threes. Not only does that obviate your use of modulus, but it also eliminates the need for more than one for loop (assuming you actually needed more than one using the method you first attempted, which looks completely wrong).

I also get the impression that you don't completely understand the basic escape sequences in C. For example, '\t' is the escape sequence for horizontal tab, not table like you seem to suppose. Furthermore judging by your code I'm not entirely sure how you expected '\t' to generate a table anyway. Take a look at this page for a list of common escape sequences in C and C++. You can get a more complete picture by looking at the ASCII chart if you wish.

Despite its relatively short length I spotted a few more serious flaws in your code which I did not address above. I recommend that you completely throw it out, and start again based on your hopefully-more-thorough understanding of the problem.

I'm supposed to write a program that counts by 3's using a for loop with the increment clause either being 1 = i + 3 or i + = 3. So far this is what i hav

The increment clause is the third and last clause of the for loop statement. You have mistaken it for the first clause. You initialize i to itself + 3, which means you use i before you initialize it. In C, this is undefined behavior, i.e. the value of i will be random garbage. No wonder your program is not behaving the way you wish.

You increment i by 1 instead of 3, but then you filter out the non-multiple of 3 values with if statements. This shows you misundertood the question. Increment i by 3 and remove the if (i % 3) statements.

I suggest you start by writing a program that prints the following with only a single for loop and a single printf (no if statements):

6
9
12
15
18

This will provide the correct basis for the rest of the program. Once you have that, figure out how to print the 3 other columns (hint: use an inner for loop). Once you have that, print the column labels (A - A+3).

Finally, how do you run your program? Simply running the compiled .exe from a command prompt will make it hard to understand your errors. It would very helpful for you to use an IDE and launch your program in the debugger (F5 in most IDEs). When an run-time error is detected, it'll show you exactly where and what the state of the program is at that point.

Your program is far more complicated than it needs to be. You already have the answer to the problem in your description. The iterator in your for loop should be i += 3 rather than i++ to use the loop to count by threes. Not only does that obviate your use of modulus, but it also eliminates the need for more than one for loop (assuming you actually needed more than one using the method you first attempted, which looks completely wrong).

I also get the impression that you don't completely understand the basic escape sequences in C. For example, '\t' is the escape sequence for horizontal tab, not table like you seem to suppose. Furthermore judging by your code I'm not entirely sure how you expected '\t' to generate a table anyway. Take a look at this page for a list of common escape sequences in C and C++. You can get a more complete picture by looking at the ASCII chart if you wish.

Despite its relatively short length I spotted a few more serious flaws in your code which I did not address above. I recommend that you completely throw it out, and start again based on your hopefully-more-thorough understanding of the problem.

+xorangekiller,

You are right, I do not really understand C, or rather programming in general....this is a learning experience for me and unfortunately it is coming at me faster than I am understanding it. I understand that \t is a horizontal tab, I get that, but I'm not quite sure how to do this one. I now am getting run time errors, so I'm closer to solving this puzzle than I was before, and for your insight I thank you. Code is hard for me to understand, and honestly it has been a lot of trial and error, including completely restarting from scratch. So far this is what I have, but I'm not understanding how to do the printf statement.

LOL! I'm not sure what my professor was thinking when he made this assignment question to be honest. I'm not following his logic very well let alone the logic of C. I'm sorry to keep posting but I'm trying to work though this as much as possible. So...with that being said this is what I have:

At least now I'm getting somewhat of the formatting that is required. I'm obviously not getting this at all unfortunately. Just pretend that you're explaining this to a child, then maybe I'll understand this because I'm completely lost.

Do I need to first initialize a printf statement before the first if statement to get the headers when I'm using the \t?

The proper algorithm will get you half way there. Your current issue seems to be evenly split between misunderstood syntax and faulty logic. I recommend that you read the printf() documentation in particular.

and it gave me the headers for the columns and I put it before the for loop. Now I'm trying to get the printouts under those headers. And now that I noticed the math is completely wrong, 6 + 4 != 12....hmmm. Or am I reading the problem wrong? Is each A+# the original number in A + whatever number is associated by A?

And now that I noticed the math is completely wrong, 6 + 4 != 12....hmmm. Or am I reading the problem wrong? Is each A+# the original number in A + whatever number is associated by A?

Based on your initial description I think you are supposed to be computing the result of the three latter columns (A + 2, A + 3, and A + 4) based on the contents of the multiple-of-three-number in the first column (referred to as A in your header and assigned to i in your loop). For example, if i=3 then A=3, A+2=5, A+3=6, and A+4=7.

Based on your initial description I think you are supposed to be computing the result of the three latter columns (A + 2, A + 3, and A + 4) based on the contents of the multiple-of-three-number in the first column (referred to as A in your header and assigned to i in your loop). For example, if i=3 then A=3, A+2=5, A+3=6, and A+4=7.

What?! Where did you get that from? Isn't there some math prerequisite for your programming class?

If (A=i)

A+2=i+2, A+3=i+3, A+4=i+4

Okay I missed that, sorry for the airheaded math...just been at this problem for a long time and obviously not thinking clearly. I do apologize for the mathematical errors. And again,thank you for all of your help.