Author | Message |
---|---|
jgarc629
Posts: 76
|
Posted 13:38 Mar 19, 2017 |
So my code displays: 10 9 8 7 ... 1 10 9 8 7 ... 1 10 9 8 7 ... 1 ... instead of 10 10 9 10 9 8 .... Same issue with the letters. I currently have two loops per each pattern, will I need a third? Any hints on what I could do? Last edited by jgarc629 at
13:38 Mar 19, 2017.
|
Arnav98
Posts: 48
|
Posted 13:41 Mar 19, 2017 |
No. U just need 1 nested loop for both of the patterns. Try looking at it this way...1st row 1 number, 2nd row 2 numbers, 3rd row 3 numbers and so on. Keep this concept in mind while designing your loop header. Also go through the stars example in the loop2 slides. |
jzunig20
Posts: 38
|
Posted 13:42 Mar 19, 2017 |
just mess around with the boolean expressions and the initial itteration variable inside the for loop, see the different patterns by changing the logic up a bit trial and error i guess |
jzunig20
Posts: 38
|
Posted 13:44 Mar 19, 2017 |
not necessarily 1 nested loop for both, it may be possible, but for now i think its easier to get one working at a time since we're barely getting comfortable with loops in general |
sdo8
Posts: 54
|
Posted 14:56 Mar 19, 2017 |
"You will want to use printf to get the spacing correct." , "HINT: You will need to use nested loops for this one. Each pattern is its own set of nested loops." - CS2011 HW08P04 Nesting for-loops would make this problem much more simple and less cluttered. If your assignment is due online at 11:59 PM at midnight, and you want to start at 1:59 PM, you're going to have to start right away, or during the 0th hour. So, for ( int hours = 0; hours < 10; hours++) { ( Do.Homework() ) } For each hour after the 0th hour ( or 10 increments [0,1,2,3,4,5,6,7,8,9] ) you'll be able to complete your homework and turn it in on time. However, if you have this: for ( int hours = 1; hours <= 10; hours++) { ( Do.Homework() ) } For each hour after the first hour, ( or 10 increments, once again, [1,2,3,4,5,6,7,8,9,10] ) notice how you'll complete your homework, but you won't be able to complete it and turn it in on time. Last edited by sdo8 at
14:57 Mar 19, 2017.
|
jgarc629
Posts: 76
|
Posted 19:37 Mar 19, 2017 |
I got Pattern 1 running good now, but now Pattern 2 goes z Y x W ..... A z Y x W ... b .. z
it's basically displaying what I want backwards/mirrored. Any hints for that one? |
jzunig20
Posts: 38
|
Posted 22:26 Mar 19, 2017 |
try tracing your code for at least 1 iteration and take a look at what you're printing first and change it to what it should be
Last edited by jzunig20 at
22:27 Mar 19, 2017.
|