Troubleshooting this TutorialSometimes, even though you try hard to understand the information in a tutorial, things don't work out quite like you want it to. This page is here to help you resolve any problems you might be having with the tutorial on decision making in C#. The Common Mistakes section describes common problems that people have when doing the things in this tutorial, and how to resolve them. The Frequently Asked Questions section describes questions that people have that aren't related to mistakes, but rather, trying to understand the stuff better or exploring how it can be used. If your problem or concern isn't addressed here, feel free to add a comment below, so that I know where you're having trouble. I like to keep these pages fairly clean, so I may remove comments that I felt like have been addressed. If I remove your comment and you don't feel like the problem has been fixed, repost the question and we'll take another look at it. If a tutorial has a mistake in it, I will fix the mistake and reply to the comment with a brief explanation. However, after a couple of weeks I'll likely go back and remove the original comment as well as my reply, because, hopefully, the problem will have been fixed, and it won't be a concern any more. |
Common MistakesNone listed yet… |
Frequently Asked QuestionsNone listed yet… |
I've followed the tutorial so far. However, as im new to programing, ive become confused. I don't understand why the solution you posted for the 'assignment' causes the picture you said to try and make. The spaces thing in partictular confuses me, i assumed it would be columns and rows, and even after seeing the solution , i can not fathom why typeing those things makes that picture.
Let me start off by saying I'm glad you've made it this far. Hang in there. This looping assignment is not trivial.
Let me also say that there is always more than one solution to every programming problem. You could have used a different approach (maybe like the columns and rows thing you bring up) and get the task done.
My first suggestion is to forget the code you've seen (but not the concepts) and go back and try to write the code for the first two examples from scratch. If you can pull off those two, then making the leap to the last one (by far the hardest of the three) is quite a bit easier to do.
Seriously. Go try it. (Maybe you already have.) Then give the last one another shot.
Also, if you're able to get the first two problems on your own, but the last one is causing you a ton of trouble, don't worry about it. Give it a shot, and then move on. If you can do the first two, you have nothing to worry about.
Let me also try to explain the code I've written in more "normal" terms.
Let's look at it this way. I have a total of six lines. So I know I'm going to have a loop (the outer loop) that goes from 1 to6 (or rather, 0 to 5, because programmers love starting at 0 instead of 1).
On each line, I'm going to print out a certain number of spaces, followed by a certain number of stars. That's what my two inner loops are for. The trick is figuring out how many.
Let's do this:
The trick here, is to find the pattern. Is there a way we can generalize it? Think about that for a minute. If you look at that table, there's a pattern. Is there a way to say, for any given line, how many spaces and how many stars to display, based on the row number? What do you think?
The number of spaces is the easier of the two. From looking at the table, you can see that we basically start at 5 spaces per line, and end at 0. For any row n, the number of spaces that we print will be 5 - n.
To be honest, you shouldn't need to loop backwards and count down, like I've done in the sample code. I should probably go change that, to make things simpler.
The number of stars to print is a little more challenging. But if you look at it, you can see that we start with 1, and go up by two for each row. For row n, we print out n * 2 + 1 stars.
With all of that in mind, try working through the code one more time. Hopefully, this time it makes more sense.
If you want, here's another interesting challenge to try to print out:
Post preview:
Close preview