Looping Problem

How to do the problem below using loop?

Input numbers until the user types a 0, then output the product of the non 0 numbers: e.g., if the user types 2 4 6 0, the program should output 48
just loop with condition

such as :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int main()
{
   int input = 1;
   int out = 1;
   while( input != 0 ){
        out *= input;
        cin >> input;
   }

   cout << out;

   return 0;
}


If someone could do the problem, that'd be nice. :)
#include <iostream>

using namespace std;

int main()
{
int a,b;
a = 1;
b = 1;
while( a != 0 ){
b *= a;

cout<<"Please enter the number: "<<endl;
cin >> a;
}

cout<<""<<endl;
cout <<"The product of the numbers you entered are: "<<b<<endl;


return 0;
}
Topic archived. No new replies allowed.