+ 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.

20th Jan 2022, 7:29 AM
hanie
hanie - avatar
24 odpowiedzi
+ 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
20th Jan 2022, 10:38 PM
JaScript
JaScript - avatar
+ 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.
20th Jan 2022, 8:06 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 2
Quoi Runtime that is awesome! Thanks a lot.
22nd Jan 2022, 6:47 PM
hanie
hanie - avatar
+ 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!
25th Jan 2022, 12:53 PM
HungryTradie
HungryTradie - avatar
+ 1
Jonas your right. I added
20th Jan 2022, 7:52 AM
hanie
hanie - avatar
+ 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)
20th Jan 2022, 12:54 PM
hanie
hanie - avatar
+ 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.
20th Jan 2022, 1:43 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 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...
20th Jan 2022, 1:45 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
JaScript thanks alot ❤❤❤ you don't know how it means to me.
21st Jan 2022, 6:19 AM
hanie
hanie - avatar
+ 1
hanie You are welcome!
21st Jan 2022, 10:18 AM
JaScript
JaScript - avatar
+ 1
Quoi Runtime I got the answer thanks
21st Jan 2022, 4:32 PM
hanie
hanie - avatar
+ 1
Wer hat gefragt
21st Jan 2022, 8:37 PM
teyo_008
teyo_008 - avatar
+ 1
How
22nd Jan 2022, 7:20 AM
Surendra kumbhalkar
+ 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
22nd Jan 2022, 3:52 PM
hanie
hanie - avatar
+ 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
25th Jan 2022, 11:25 AM
HungryTradie
HungryTradie - avatar
+ 1
HungryTradie that is so good, thanks. But only one problem. ! Should be upest and leftest
25th Jan 2022, 12:44 PM
hanie
hanie - avatar
+ 1
HungryTradie wish you the best🌝
25th Jan 2022, 12:54 PM
hanie
hanie - avatar
+ 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.
25th Jan 2022, 1:46 PM
HungryTradie
HungryTradie - avatar
26th Jan 2022, 6:53 AM
HungryTradie
HungryTradie - avatar
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.
20th Jan 2022, 7:40 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar