do while statement

Hi can anyone help me with this? so when i enter 0 i want no processing of any numbers and just end.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  #include <iostream>
using namespace std;
int main()
{
   int number, product = 1, count = 0;
   
 do
   {
      cout << "Enter an integer number to be included in the product"
      << endl << "or enter 0 to end the input: ";
      cin >> number;
      product = product * number;
      count++;
      cout << "Enter an integer number to be included in the product"
         << endl << "or enter 0 to end the input: ";
      cin >> number;
 } while (number != 0);

   if (count > 0)
   {
      cout << endl << "The product is " << product << "." << endl;
   }
   system("pause");
   return 0;
}
And does the program not exit when you enter 0?
it does. except that you have to enter 0 twice.
To remove this behavior, remove from line 14 to 16 inclusive
it making me to enter 0 twice. when enter 0 initially, i want the program to end without any process or error. sorry for the confusion. what i want is when i enter 3 or 4 number and 0 at the end it will sum it up and show answer and want program to end when i enter 0 instead greater than 0
Last edited on
You need to rethink your logic...

number is your loop control variable... number is also used to calculate your product...
0 * anything is 0.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <iostream>
using namespace std;
int main()
{
   int number, product = 1, count = 0;
   
 do
   {
      cout << "Enter an integer number to be included in the product"
      << endl << "or enter 0 to end the input: ";
      cin >> number;
      product = product * number;
      count++;
 } while (number != 0);

   if (count > 0)
   {
      cout << endl << "The product is " << product << "." << endl;
   }
   system("pause");
   return 0;
}


Fixes the need to input 0 twice but does not solve the logic problem.
Registered users can post here. Sign in or register to post.