Pages: 12
So is my loop and array working? can I combine them? or do i have to do more
I just showed you what the combined loop and array should look like in my last post. The last code that you posted is not how you should be doing things; once you get more than a few elements, it becomes really dumb to not use loops. I posted what that program would look like using loops; do you not understand it? I can explain it step by step if that's the case.

Just fyi, I've got 30 more minutes of being bored at work, then I may not be posting so often.
Could you explain it please? I'll let you go after that. Thanks for all the help by the way, you've helped so much. Thank you.
Ok, hopefully these comments will clear things up:

 ``1234567891011121314151617181920212223`` ``````#include int main () { int arr[15]; //declares integer array with 15 elements for (int i = 0; i < 15; i++) // i starts at 0, and will increase by 1 each time the loop runs // once i reaches 15, the loop will stop executing, because arr[15] is outside of our array { arr[i] = (i + 1) * 100; // In your test program you assign 100 to element 0, // 200 to element 1, and so on // this statement takes the element number (i), adds 1, then multiplies by 100 to get 100 for element 0, 200 for element 1, etc } char str[] = "c program"; // this is unchanged for (int i = 0; i < 15; i++) // same loop as used before { printf("%d: %d\n", i+1, arr[i]); //we want to print 2 numbers, the element number + 1 and the value in the array at that element //so we do i+1 to get "1" to print for the value in the 0th element } printf("string: %s\n", str); // this is unchanged return 0; } ``````

If your book doesn't adequately explain all this stuff, you should get a different book. My intro book taught me everything very clearly. Please keep asking questions until you understand this stuff. This board gives me stuff to do while I'm bored waiting for the 4 day weekend to start :)
What's the name of the book? I'll definitely buy it! sorry if i seem like you're just talking to a wall, i've literally only been doing C for the past 3 weeks. I'll keep post questions and once again, thanks for all the help.
I actually started with C++ and have never even looked at a C book; I just took what I knew of C++ and learned C from online stuff. There's honestly so much stuff online that you could learn pretty much any language without ever touching a book. cprogramming.com has good tutorials; here's one on loops: http://www.cprogramming.com/tutorial/c/lesson3.html. Some books just don't explain things clearly at all, and it's frustrating when those are the ones the professors choose.
I really hope all of this sinks in. How do you recommend I get better at it? Do I have a lot of work left in my assignment? Was that the harder part?
Topic archived. No new replies allowed.
Pages: 12