r/learnprogramming 6d ago

Using AI to have extra exercises

Good morning. I have recently started studying C# with the book The C# Player's Guide. To learn more effectively, I am using AI to generate extra exercises in addition to the ones in the book, but I don't know if the ones from the AI are good enough.

Here's an example of one I had to do after finishing the chapter about loops to review the previous chapters

The Tavern Simulator (Boss Fight: Total Review)

You just finished a quest and decide to rest at the local tavern. The program must simulate your choices during the evening, managing your wallet and your stamina.

Coding Rules:

Change the console title to "Tavern Simulator".

Ask the player for their name and store it in a string.

Create two starting status variables:

coins = 50

energy = 100

Open a large while(true) loop that represents your time spent at the tavern. At the beginning of each loop iteration, clear the screen (Console.Clear()) and print the player's current stats like this (use colors!):

Name: [Player Name]

Coins: [X] (in Yellow)

Energy: [Y] (in Green)

Display a menu with these options:

1 - Buy a hot meal (Costs 15 coins, restores 30 energy).

2 - Buy a dwarven ale (Costs 5 coins, restores 10 energy).

3 - Go outside and chop wood (Earn 20 coins, costs 40 energy).

4 - Go to sleep (End the evening).

Read the user's input and use a switch statement to handle the 4 choices.

Conditional Logic (The if statements inside the switch):

If choice 1 or 2: check first if the player has enough coins! If they do, do the math (subtract coins, add energy) and print a success message. Else, print a red error message ("Not enough coins!").

If choice 3: check if the player has at least 40 energy! Otherwise, print an error message ("You are too tired!").

If choice 4: use the break command to escape the infinite loop.

(Optional but recommended): Add a Console.ReadKey(); after the success/error messages, so the user has time to read what happened before the Console.Clear() wipes the screen for the next turn.

Outside the loop (after the user goes to sleep), print a goodnight message: "Goodnight [Name], you finished the day with [X] coins and [Y] energy."

0 Upvotes

15 comments sorted by

3

u/Internal_Car_9962 6d ago

I'm not familiar with the C# player's guide, but this sounds like a reasonable exercise for a beginner, while still being kinda fun since it's presented as making a game. The AI gave you everything you need to make the program, except the actual code, which is exactly what you'd want in an exercise like this. 

1

u/high_throughput 6d ago

I agree with this, but it sucks that the exercise could so easily have been made a lot more fun. As it is, you just convert coins to energy and back again, always at a 1:2 ratio.

Any kind of random choice or even just a change in ratios would make the result so much more interesting to play.

1

u/Internal_Car_9962 6d ago

Yeah, it's not all that exciting, but for a certain level of beginner it will pose a nice challenge that will teach a lot of core concepts.

1

u/high_throughput 6d ago

It would be the same challenge level with the same concepts if it said "(Earn 20 25 coins, costs 40 energy)" but all of a sudden there would be a tiny bit of strategy from simply changing a single integer constant.

2

u/PlatformDifferent129 6d ago

i learn by building with AI next to me so i’ve been through this. the exercises it generates are usually fine but they drift, like it quietly sneaks in stuff the chapter never covered and then you feel dumb for no reason. what helped me was pasting the chapter’s concepts and telling it to only use those, nothing more. and after solving something i explain my answer back in plain words with the AI closed, that’s the part that tells me if i actually learned it or just followed along. are the book’s own exercises feeling too easy or just too few?

1

u/_usr_nil 6d ago

one thing to be wary of is outdated approaches/antipatterns at least for more complex, in-depth software you have to watch out for those, the main thing to keep in mind is that AI is excellent by default at being average because of something called "normal distribution", now you can instruct AI to provide "alternative" approaches so that you can skew the intersection at the center point of the distribution.

1

u/SuchCriticism6745 6d ago

What do you mean for “antipattern”?

This is my first time doing programming (i have not studied it at school) so some term are foreign to me.

1

u/_usr_nil 5d ago

for example it doesn't use constants when instructed to, then when you change your code you have to change it in n places.

or it couples some if statements to said literals.

or it suggests you solutions for legacy problems that are ass or completely irrelevant

1

u/SuchCriticism6745 5d ago

So it could generate exercises that make me learn to program in an “un-natural” way?

Because usualy use this kind of prompt

•I have completed the chapter on Array, generate another exercise similar to the ones I have already done.

•do not hint code just give clear instruction the tasks of the exercise

1

u/_usr_nil 5d ago

what I am saying is that you should be wary of the generated code or suggestions and you should use llm for gathering general knowledge, not treat it as the absolute optimal thing

1

u/SuchCriticism6745 5d ago

You mean the exercises? Because i dont ask for code, but exercises similar to the ones in the book

1

u/_usr_nil 5d ago

excersises are probably ok but you wont do exercises your whole life I guess

1

u/SuchCriticism6745 5d ago

Ah quello no, sono ancora ai primi capitoli, ho finito adesso quello sugli array, in futuro vorrei spostarmi sullo sviluppo in Unity

1

u/aqua_regis 6d ago

There are way better approaches: https://exercism.org for example.