My do-while loop only counts every other step. Help?

Hi everyone, I'm trying to complete a program that sort of snowballs multiplication, for lack of a better word, and after about an hour of tinkering with the code to make it work, I've gotten to the point where it basically only factors in every OTHER input leading up to ending the loop. Can anyone explain what I'm doing wrong? I modeled my code after one that was given as an example, but I cannot figure out what I'm doing wrong. Any help would be appreciated!

Here's my code so far.

int num, product = 1, count = 0;

do
{
cout << "Input a number to include in the product"
<< endl << "or enter 0 to end the input: ";
cin >> num;


if (num != 0)
{
product = product * num;
count++;

cout << "Input a number to include in the product"
<< endl << "or enter 0 to end the input: ";
cin >> num;

}
}

while (num != 0);
if (count > 0)
{
cout << "The product is " << product << "." << endl;
}
You're asking for input twice each time the loop iterates. Remove the 2nd instance (the one inside the if statement) and it should work.
Ah that fixed it, and that definitely made sense. Thank you very much for both the answer and the explanation!

I'm very novice at this and I'm really only doing this course to fulfill a graduation requirement, but I am trying to learn it as best I can. Thank you very much!
Topic archived. No new replies allowed.