Nachdem ich das Problem wie folgt gelöst habe, hab ich mal bei den anderen ihren Problemen geschaut.
Eine doppelte Bedingung in die Klammer zu packen (b<=c && c<=a) war halt bisher nicht erklärt, wie kommt man darauf? Wäre auch leichter wenn man mit "and" die Bedingungen verknüpfen könnte, oder geht das irgendwie? Also if, and if usw.
Meine Lösung:
int m;
int x;
if (a<b)
x = a;
else
x = b;
if (x<c)
m = x;
else
m = c;
return m;
Knattertoni
Level 4
Wie kommt man auf die Verkettung der Bedingungen in der Klammer?
Gelöst
Kommentare (5)
- Beliebt
- Neu
- Alt
Du musst angemeldet sein, um einen Kommentar schreiben zu können
Knattertoni
4 Mai 2021, 08:21
Thank you for your feedback.
Saving memory seems wise. What I was asking is, how should I know that you can add 2 terms in the bracket with the "&&". In the course they never spoke about it.
It will be helpful in the future of course, so I am glad having looked after other solutions.
+1
Guadalupe Gagnon
4 Mai 2021, 16:03nützlich
You don't need it for this solution. It most likely will be brought up in a lesson further along.
Also, don't get hung up on "they haven't taught it yet". Being a professional programmer literally equates to 10% actually writing new code, 40% researching how to do something, and 50% debugging. Thinking that you have to be specifically told something before you use it is going to really slow you down a lot.
And.... I solved every task so far on this site using only what they taught me. It can be done, though it takes some creativity to apply the knowledge to the desired results. The tasks are designed to challenge you, and as I said in my previous post it is good that you solve them first before looking up other solutions. Once you face, and solve, the sub-problems that need to be solved to complete a particular task you can better understand the solutions to those problems that other people have come up with. You will learn programming much faster if you do it this way.
Just remember that there are a lot of people that take this course that are not beginners. They will use things that you have never seen because they have. Don't be afraid to look up those things you see and don't understand. Once again it will speed up your over learning.
+5
Knattertoni
5 Mai 2021, 12:35
Ok, that is a good motivation, thank you again for your detailed answer :)
+1
Anonymous #10982004
21 April 2022, 10:57
An insanely great and inspiring point of view. I like 🥰
+1
Guadalupe Gagnon
3 Mai 2021, 14:16nützlich
Any solve is a good solve. It is good that you look at other solutions after you solve a task, you can learn a lot of new concepts this way or see different problem solving techniques.
Doing compound expressions for this task is not going to be an efficient solition. The solution that you came up with has exactly 2 Boolean checks with 2 ints being declared (x and m) as extra memory use. You can actually improve it by removing the additional memory and solve this correctly with only 2 Boolean checks (think using the memory you already have available).
With the line that you shared, (b<=c && c<=a), this single expression can not arrive at the correct answer. This means you need at least one more Boolean check if not more. That would make your code more efficient.
+2