0

how to do this?

this code is generating a random equation. how can i add that when i write 'points' insted of the answer of the equation, the system shows me how many points i have (you gain points by getting answers correct). this code wont work well on SoloLearn because SoloLearn doesnt support multible Scanners. (run this code on another platforn). code: https://code.sololearn.com/crJoNyj46O2T

28th Jun 2020, 9:23 PM
Yahel
Yahel - avatar
10 odpowiedzi
0
You don't need multiple Scanners; But I have 5 tips for you. 1. Use a String to accept input from Scanner. 2. Your current code only asks one time, after that it ends at once. To make it continuous, use a do-while loop and exit if user enters something like "exit". Another else if for "exit" where it breaks the loop. 3. To store points, use an integer variable to increment whenever got correct answer. 4. Add the "points" as another if-else to show the current point or score. 5. Simplify your switch statement, put the scanner and checking of answer outside the switch. Inside the switch should only be the computation. Here is my sample code, https://code.sololearn.com/ctL6lP807s9X/#java Hope you get my idea. You can try to execute it here, https://onlinegdb.com/SJquHiLRL
28th Jun 2020, 10:16 PM
Mike Rustia
+ 1
You can also run and check it here to interact with the command line directly. https://onlinegdb.com/rkkKqo80I
28th Jun 2020, 11:19 PM
Mike Rustia
28th Jun 2020, 10:22 PM
zemiak
0
4. you are repeate 4x same code for check right value, it is better to write method for it or check it one time after switch()
28th Jun 2020, 10:49 PM
zemiak
0
zemiak , how should the method look like? i cant make it happen...
29th Jun 2020, 10:55 AM
Yahel
Yahel - avatar
0
Mike Rustia , Thanks!!!
29th Jun 2020, 11:02 AM
Yahel
Yahel - avatar
0
NP, happy to help
29th Jun 2020, 11:13 AM
Mike Rustia
0
Mike Rustia how can I add that when I get 5 correct answers in a row - i get a bonus of 2 points? https://code.sololearn.com/cedxEkG8jaeC/?ref=app
29th Jun 2020, 2:52 PM
Yahel
Yahel - avatar
0
if it is continuous without break, then try another variable, bonusCount=0. if correct increment it, and check if already 5. else if wrong, reset to 0 again. once it reaches 5, then add 2 points, and reset the bonusCount to 0 again.
29th Jun 2020, 2:56 PM
Mike Rustia
0
Mike Rustia , thank you! didnt think about that... my first thought was making a for loop..
29th Jun 2020, 7:38 PM
Yahel
Yahel - avatar