in the section on using for loops with a continue statement, pgs 139-140, I get a different result for the variable "product" depending on whether I compile it and run it from a command prompt, or whether I press ctrl+F5 in visual studio (running without debugging). This happens when I continually enter the number 0 for the cin value variable. (ten 0's)
running at the command prompt, the value for "product" at the end is 1, as it is initialized in the program
With ctrl-F5, it is 0.
Anyone know what this is? Not that it's important in the big scheme of things, but I'd like to know why there is an inconsistency.
thanks in advance
and here's the code for cut and paste. Also, you might try uncommenting my comments lines, building, and then running from the DOS prompt - for some reasons, the lines, when uncommented, make the value change too.
// for loop
int i = 0, value = 0, product=1;
for (i=1; i<=10; i++)
//cout << "product now equals " << product << endl;
//cout << "value now equals " << value << endl;
//cout << "product * value now equals " << (product *= value) << endl;
cout << "Enter an integer: ";
cin >> value;
if (value == 0)
product *= value;
cout << "Product (ignoring zeros): " << product << endl;