문제

I have been trying to program the 3x 7 trick. The full code is available here: https://codereview.stackexchange.com/questions/9419/programming-of-3-x-7-trick.

I am stuck at step 5.

enter image description here

I have this error when i type in the value for the row.

enter image description here

Not sure what the error is. Need some guidance.

step 6: enter image description here

도움이 되었습니까?

해결책

That error comes from the back_to_array function, where you have a typo in the condition of the inner loop. It should be j < numRows instead of i < numRows.

다른 팁

The main issue is the mistake with i < numRows instead of j < numRows.

As per requested, here are some other modifications you could and should implement:

  • Write printf("%8i", ... instead of printf("%i\t", ..., since the latter is likely to spread out the numbers unevenly.
  • Sanitize your input. Right now, you can make the program crash by inputting strange values. (Also, give the user a hint about whether to use the values 0, 1, 2 or 1, 2, 3.)
  • Right now, you're not shuffling row 0 and column 0. For instance, you start with column 6 and go through the columns one by one, but you stop as soon as you reach 0, before entering the loop again.
  • There's a problem where you quite often notice that the same numbers occur together on the same row. I believe, although I'm not completely sure, that the problem is that you're sorting the rows. The point of placing the selected row in the middle of the deck all the time, is to make the selected card move towards the center. If you sort the row, you allow the card to move away from the center. I commented out the sorting and couldn't notice the problem anymore. Is there a reason why you sort the rows?
  • Regarding design: Personally, I'd not display a shuffled array and wait for a keystroke before beginning. Instead, I'd write the instructions and immediately ask the player to enter a number. I always tried to enter a number already after the first array had been displayed. Very annoying. :)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top