I have to make an Arduino program, that simulates throwing with 5 dices. (for a yahtzee game).
int five_dices[5];
void setup()
{
Serial.begin (9600);
randomSeed(analogRead(0));
Serial.println ("Throw 5 dices");
for(int i = 0; i < 5; i++)
{
five_dices *= random (1,7);*
<em> Serial.println (five_dices *);*</em>
_* }*_
_*delay (2500);*_
_*Serial.println ("Choose dice(s) to hold");*_
_*}
*_ This is what i understand, i simply cannot understand how i would "hold" som of the dices, or in other words hold some of the arrays variables, and rethrow (randomize) the rest. Hope some one can guide me, in the rigth direction with this.
Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is the forum software can interpret parts of your code as markup (for example, the italics in your code above), leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar, then you can manually add the code tags:
```
// your code is here
```
Using code tags and other important information is explained in the How to use this forum post. Please read it.
A simpler system for user input might be to get the user to enter a string with all the dice that s/he wants to hold. For example "145". Then that can be parsed by iterating over the received array and subtracting '0' from each value to get the index of the HOLD array. Just ignore values that are out of range or values after the 6th array element - for example if the user entered 183444455 the 8 and the 5s would have no effect (foolish user).
Robin2:
A simpler system for user input might be to get the user to enter a string with all the dice that s/he wants to hold. For example "145". Then that can be parsed by iterating over the received array and subtracting '0' from each value to get the index of the HOLD array. Just ignore values that are out of range or values after the 6th array element - for example if the user entered 183444455 the 8 and the 5s would have no effect (foolish user).
...R
For sure. My way is kinda agricultural. Would be a good exercise for the OP to make it better using a method like yours.