+ 1

Why does this not run? I had it running until I tried to make it grammatically correct.

https://code.sololearn.com/c3Jvl6odJ8Q6/?ref=app

14th Dec 2019, 3:31 AM
Colter
Colter - avatar
8 Respuestas
+ 3
Colter that's what this community is for! It's okay to make small mistakes, and don't hesitate to ask again as long as you have tried it and failed. Glad I could help!
14th Dec 2019, 4:08 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
Colter that is not an error, it's a warning. I just read you code, you have many errors there. 1. After the for loop, you forgot to use the brackets {} 2. Inside the if statement, you're creating a new variable, therefore the condition will always be true 3. Also, inside the same if statement, using: if (roll == 8 || 11 || 18) will always be true, because even if roll is different than 8, 11 and 18 are considered as true (any value different than 0 is true) 4. To check if a variable is equal to something, you use ==, and not just =. = is used for assinging a value, and == to check if it's equal to a value. 5. When you recalled the function dieRoll(), you're actually generating a new value, so even if the variable roll is equal to 8, 11 or 18, the output of the function will be completly different. Here is a fix: 1. Just add the brackets 2-3. Don't create a new variable, but check the condition with: if ( roll == 8 || roll == 11 || roll == 18 ) 4. use == 5. Make new variable: int roll = dieRoll();
14th Dec 2019, 3:59 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
Here is a small fix to your code: https://code.sololearn.com/c17meXCSN9Ae/?ref=app
14th Dec 2019, 4:00 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
What did you understand from the error message ?
14th Dec 2019, 3:36 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
Colter, dieRoll is an integer, you cannot name a function and an integer with the same name, it must be different.
14th Dec 2019, 3:41 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
0
That I couldn't use the function in the output, but that's how it ran when I only had one.
14th Dec 2019, 3:40 AM
Colter
Colter - avatar
0
Well I fixed half of it now. Thank you. Now I get an output and an error.
14th Dec 2019, 3:43 AM
Colter
Colter - avatar
0
Wow. Thank you. I was close. I'm new to coding and still figuring it all out. I really appreciate it.
14th Dec 2019, 4:06 AM
Colter
Colter - avatar