22 lines
711 B
Markdown
22 lines
711 B
Markdown
|
The normal 6 sided dice is pretty boring. So how about rolling a D20 or a D8?
|
||
|
A D20 is a dice with 20 sides and a D8 one with 8.
|
||
|
But we don't want to write the function all over again.
|
||
|
You could also rewrite the dice function to take the amount of sides as a parameter.
|
||
|
|
||
|
## Knowledge
|
||
|
|
||
|
_Remember_: Parameters are written between the parentheses and are separated with commas.
|
||
|
|
||
|
Like variables parameters have a type and a name. So when you have a function like:
|
||
|
|
||
|
int add(int a, int b)
|
||
|
{
|
||
|
return a+b;
|
||
|
}
|
||
|
|
||
|
and call it like this:`add(5+9);`, then a = 5 and b = 9 and it will return 14.
|
||
|
|
||
|
## Task
|
||
|
|
||
|
Rewrite the function, such that it take a parameter to determine, what kind of dice you roll.
|