vendredi 16 octobre 2020

Optimizing conditional programming: if/else statements affecting performance [closed]

So I am a beginner programmer, and I wrote a program that when you input 3 angles and 3 sides of a triangle it evaluates via math if given those angles and sides the triangle may exist, and then it checks in order:-is it a triangle with a 90 degree angle? if yes, check if both the adjacents are equal, and so on.

The code is working perfectly, but using so many if-else statements makes it really annoying. How can I improve these? I tried replacing them with switch-case statements but they dont seem to make it any faster, and even if they did, what if I wanted to test strings, and not numerical values? What are the best get-arounds for this problem?

Aucun commentaire:

Enregistrer un commentaire