0

I am making a console maths test that asks a few random addition, subtraction, multiplication, division, power and square-root questions based on the difficulty level the user chooses.

I am trying to make my code more advanced by automatically setting the difficulty to the harder level or easier level the next time he runs the code depending on what score he got the last time he did the test. For example, if he chose the Normal level and gets a score of 1/10, the next time he runs the code he should automatically be doing the easy level.

I thought "environment variables" is something to look into to save state but it does not look anyone have tried to do so. It very well could be I'm starting very wrong route with environment variables.

d51
  • 316
  • 1
  • 6
  • 23
  • This is pretty broad for stackoverflow, but the short answer is that you have to save the user data (previous answers, scores, difficulty, etc) somewhere. Often this is done with a database, but you could persist the information to the file system or registry. Search online for different options, give something a try, and come back if you get stuck on something specific!! – Rufus L Apr 22 '20 at 03:28
  • Is this a system design question? Because your question (in the title) says something about an environment variable, user input and console application. But I think you're just asking about how to save persistent settings / persistent data. I'm voting to close until you put together a more focused question. – Wyck Apr 22 '20 at 03:39

1 Answers1

1

I can think of 3 options to achieve this -

1) You can save the score object "OperationQuestionScore" value serialized to file on the local system. So the next you run your program you can read the previous score and set the difficulty level accordingly. You can find more details of serialization and deserialization - https://www.guru99.com/c-sharp-serialization.html

2) You can save the score value of the user in the registry and read it next time the program runs. You can get more details on this link - https://www.c-sharpcorner.com/UploadFile/f9f215/windows-registry/

3) You can save the value to the database. You can use above 2 options if you don't want to add DB.

Thanks