+ 4
Wondering how I should improve my code.
2 Respuestas
+ 4
Some things I spotted:
line 39 change the if to-> (x >= 0) instead of (x > 0)
Why? Because: Sqrt(0) = 0.
You should use for loops if you will just depend on an incrementation in the while loops.
ex/
int example = 0;
while(example < 10)
{
// do stuff
example++;
}
Why use a for loop instead?
When you declare the variable for your iteration it is declared as a local variable. However, you only need to use it within the scope of your loop.
For this reason while loops are generally better used if you do not always know how many times you will need to loop.
By skimming through your code, I cannot point out which area should be replaced by a for loop, as I'm not sure which variable would be necessary later on.
Which poses another problem. By looking at your code with all these "q = x" "d = w" it becomes harder to read. Try using names of variables so we know you need the variable and the use of the variable just by the name.
ex/
char input;
I know this is the input from the user, just by looking at the name.
nCr function can just be void. It never uses the return value. To end a void function just say "return;". Doesn't need to return anything.
+ 2
Thank you for the feedback!