-2

can I have some suggestions on how to create a calendar that says the free days of the user?

I will explain it better: I'd like to create a program (possibly in C++ or Java since we are learning that at school) that reads (maybe in a txt file or something) the days where I am busy and exclude them and then get the output of the other days.

Example:

My txt file contains:

13, 14, 20, 21, 25, 11, 3, 30

Expected output from the program

1,2,4,5,6,7,8,9,10,12,15,16,17,18,19,22,23,24,26,27,28,29,31

Sorry for the stupid question but I'm new to programming and would like to learn, thanks for any advice, and if something is unclear please let me know!

Kiriaevi
  • 5
  • 2
  • 1
    Please choose one programming language per question, not two. Those two here (java & c++) are not comparable. – deHaar Oct 17 '20 at 06:04
  • You got an answer. Now please explain why it is not what you were hoping for. I.e. put more focus on that specific programming problem you encountered while trying yourself. Since you ask about calendar handlng and not about reading numbers from a text and outputting numbers please show your code doing that, as a [mre]. Based on your code for basic input and output, answers can provide help with the remaining parts. – Yunnosch Oct 17 '20 at 06:14
  • 1
    Generally, please take the [tour], read [ask] and more specifically, read https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions – Yunnosch Oct 17 '20 at 06:17

2 Answers2

2

Language-agnostic* solution:

  1. Create an array of 31 booleans.

  2. Using the numbers in the text file, mark the values at those indexes as true.

  3. Iterate the array and print the indexes of the ones that are false.

If needed, depending on language and array definition, adjust logic to handle array indexes being zero-based.

*) For programming languages that support arrays.

Andreas
  • 154,647
  • 11
  • 152
  • 247
  • I think this is not what OP was hoping for. And I enjoy and appreciate every word of it. You got my upvote. – Yunnosch Oct 17 '20 at 06:19
0

In this answer I will focus on "I'm new to programming and would like to learn, thanks for any advice".

Whenever you want to learn, you have to DO. no amount of talking, reading and listening can replace doing the thing you want to learn. So if you really want to learn, think about your problem, verbalize a possible answer (you can write the steps you make up in to-do-comments in your IDE) and try to implement it. You will get stuck. Take a breath and think about why something is not working as you want it to and change it accordingly. Allow yourself to make mistakes. Making mistakes (and understanding them!) is the best thing you can do when learning.

You might get stuck at a point where all you can think of fails. Then is the right time to ask for help, providing information on what you already have, on what you tried so far and what you need to continue.

So for your problem: choose one language and start. When you really get stuck, ask a specific question about your problem. Don't just ask for a solution.

Andreas
  • 344
  • 4
  • 14
  • 2
    I think this risks being flagged as not-an-answer, though I think it is another one which OP will not appreciate. In line with your concept you might like https://ericlippert.com/2014/03/05/how-to-debug-small-programs/ and https://ericlippert.com/2014/03/21/find-a-simpler-problem/ Have fun reading it. – Yunnosch Oct 17 '20 at 06:28