+ 5
Help me please
How can i code this : ! # # # # # # # # # #@ # # # # # @ # # # # $ # @ # # # # @ # # If we have 4 @ One ! and one $ and the other are #, (so we have 26 #) ! Is always upest and leftest(like I have drawed) , and others are random. https://code.sololearn.com/cPUurhqR4ozg/?ref=app This is my try, it didn't work.
24 Answers
+ 5
hanie , this is solution for that based on an idea of random index of the board‘s array. Happy coding.
https://code.sololearn.com/clFs8Bdx3W98/?ref=app
+ 3
Thank you :)
Well, that is an interesting approach. Without calculating the probability of it to fail, I would guess that chances are high that it will work. There is, however, a chance that it will not. I wonder if you can imagine, why.
Here's why: there is no guarantee that your code will print one '#x27; and four '@'. So, my first thought would be how to make sure the code always does. I would make an array and fill it with '!' at position zero and '#' otherwise. Then do a random draw for one '#x27; and four random draws for '@'. It is easy to verify that a position in the array is not taken twice by this process by checking a[pos] == '#'.
Then, you need to print it as desired. You don't have that in your code, yet.
+ 2
Quoi Runtime that is awesome! Thanks a lot.
+ 2
Yep. I would %100 benefit from reading all the instructions....
That is fixed, and I've corrected the 4*$ to be 4*@.
I'm gunna try using pointers instead of char[][]. Wish me luck!
+ 1
Jonas your right. I added
+ 1
Jonas thanks.
Should I change it to multi array? I mean change it to arr[4][8]
(In the next step I should code sth that make i move by user)
+ 1
That seems to make things unnecessarily complicated, in my opinion. It would also be possible to reshape the array later, but that is rather advanced C.
I'd go with a one-dimensional array and indicate its shape on screen with parameters to a print function.
+ 1
Oh wait, I just noticed the addition there. Hm, if a 8x4 array makes things easier later on, yes, that might be a good choice...
+ 1
JaScript thanks alot ❤❤❤ you don't know how it means to me.
+ 1
hanie You are welcome!
+ 1
Quoi Runtime I got the answer thanks
+ 1
Wer hat gefragt
+ 1
How
+ 1
Quoi Runtime I want the result be like a 4×8 matrix which the "!" Has a particular place and we have one of it, then we have 4 @ one $ and 26 # which they are in random places
+ 1
G'day hanie I've also had a go at your project. My attempt is in C.
https://code.sololearn.com/cxWVjyxA9Q33/?ref=app
+ 1
HungryTradie that is so good, thanks. But only one problem. ! Should be upest and leftest
+ 1
HungryTradie wish you the best🌝
+ 1
With pointers
https://code.sololearn.com/cRiyH5sl6Wkp/?ref=app
It is very clunky, I had to use (*(grid+(i*COL)+j)) so many times to traverse the array 1 char at a time.
+ 1
G'day Quoi Runtime this almost works.....
https://code.sololearn.com/cPv8Yc2J3luG/?ref=app
0
That is unfortunately NOT how this forum works. You may ask for help on any specific problem you run in to while learning to code or attempting to write a program. However, this is not a code ordering service.
If you have tried anything, then please present your work so we can assist you. Otherwise, put in some effort to at least TRY to solve the problem. It will only be to your benefit!
Thank you.