Hey guys, so far in my C++ class I have stumbled upon a few things or just in need of some clarification. If you guys can answer me, this would be a great help!
1.) What is the main difference between break; and continue;?
I understand their main function lies within if(). For example, you make an if for when an equation reaches a denominator of 0. You would use break; which would end the loop at that point and then continue on with the program...
What exactly does continue do then, assuming that I have understood break correctly..?
2.) What is the main difference between while() and for()?
I understand that for() is technically a lot easier compared to while(). I did notice that for tends to have multiple statements such as for(i=3; i<10; i++;) compared to while which is usually while(i<4) or something...
Are there really any other differences between the two?
3.) This is what stumps me the most. So far my professor has said that every exam will have problems dealing with integers and doubles. I just can't wrap my mind around these problems. If you are uncertain of what I mean, this is an example...
3/5 * (1.25-2) + 4/3 * (2-(4*2)) + exp(3/5) + 3/4
How would you go about solving this? What is the integer and double answer?
--Does anyone know of a website with practice problems such as the above?
1.) What is the main difference between break; and continue;?
break; will exit your loop and continue with your program. continue; will end execution of the current iteration of your loop but it will continue going through the loop.
lirik wrote:
2.) What is the main difference between while() and for()?
for() has everything it needs to do a loop contained in it's structure. while() is usually testing a value that changes elsewhere, such as a boolean when something has completed. While can also be used to do a loop that will always execute one last time with the "do...while()" form. Otherwise they do the same thing, which is cause a loop in your program.
lirik wrote:
3.) This is what stumps me the most. So far my professor has said that every exam will have problems dealing with integers and doubles. I just can't wrap my mind around these problems. If you are uncertain of what I mean, this is an example...
3/5 * (1.25-2) + 4/3 * (2-(4*2)) + exp(3/5) + 3/4
exp(3/5) is an exponential number with decimal places, and value 1.25 would be a double. (Although I would use a float for this personally). Also, 3/5 and 4/3 result in values with decimals. Integers can't handle these values so a double(or a float) needs to be used otherwise you loose those decimal places.
4/3 is 1.3333, but if you put it into an integer it would simply be 1. 3/5 is 0.6, and would end up being 0 if stored as an integer. exp(3/5) is 1.8221188, and again is only 1 when stored as an integer.
Basically, integers drop the decimal values, and doubles do not.