#include <iostream>
usingnamespace 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
#include <iostream>
usingnamespace 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.