Thanks for the posts! Let me see if I can respond to some. (prepare for edits)
Quote (PumblesMumbles @ Jul 21 2012 10:54am)
The only "bug" I see is that you are counting 0 as a positive number.
As far as style, there are four things I'd call out. First, I always use brackets in if/else statements, even if the block is only one line. It makes all programs look the same and makes it easier to add more to the block later. Second, whenever you have an expression like
Code
if (whatever) {
return true;
}
else {
return false;
}
you can always just shorten that to
return (whatever);. If you'd return false in the if case and true in the else case, it can be
return !(whatever);. Third, I recommend camel case for function names (isInOrder, printResults, etc) since it makes them easier to read. Fourth, I recommend spaces between function arguments (inorder(x, y, z) vs inorder(x,y,z)) again because it makes the program easier to read.
It sounds like the last two might be decisions the professor has made for you. More important than any style preference is working in the same style as the rest of your team.
Ahhh, good point about the zero. I forgot the prof. did mention to take care of that as well.
About the if else, THANKS. I have been waiting for someone to tell me that it is a good idea to do that. I have absolutely NO PROBLEM doing the brackets even if there is only one line. I just had no idea whether doing that was good writing or not.
Will do the other things you mentioned too (spaces, and camel case)
Quote (Reynaldo @ Jul 21 2012 01:39pm)
hey, i program on c, python, you could make an infinte loop when you ask for information, and ONLY IF the information introduced was right, then you proceed to close the loop and then the program keeps going
an example in c
....
int inf=0, num1;
while (inf==0)
{
printf("\nIntroduce me one number between 1-1000");
scanf("%i", &num1);
if (num1>1 && num1<1000)
{
inf=1;
}
}
I am still searching for the best way to do something like checking a value while getting it. The prof. used do-whiles, but I am not sure what is the best way yet.
Quote (AbDuCt @ Jul 21 2012 02:15pm)
sorry for the double post but this code is horrid >.>
could do away with 1 whole variable and make the logic flow better by using a do while loop and putting your conditions in the while brackets. (using a do..while loop guarantees that 1 loop will execute before the conditions are checked while, a while loop will check conditions before a single iteration has been preformed)
Thanks for your posts. I have not learned about pointers yet in the class but probably will soon.
Can you offer a better way for me to do that cin function?
You said a while loop would work better?
This post was edited by Eep on Jul 22 2012 12:45am