Simple Multiplication in While Loop

Problem: Create a program that will employ a count-controlled while loop. The loop should prompt the user to enter a number and calculate a running product of the numbers entered. The loop should prompt the user to enter 8 numbers one at a time. Then after the loop has finished, display the product of these eight numbers.
Code:

#include<iostream>

using
namespace std;

int
main()

{

int counter = 1;

double number, mul = 0;

while (counter <= 8)

{

cout <<"Please enter a number. ";

cin >> number;

mul *=number;

counter++;

}

cout <<
"The product of the eight numbers is " << mul<< endl;

}


I can alter the program for a sum, and it works. When I run the program now, no matter what numbers are entered the output is 0. My guess is that the error is coming here:

mul *=number;


Because if change the * to a + it creates the sum. So I assumed that * would produce the product. But I was wrong. Any thoughts?
yep, what happens when you multiply a number by 0 ?

change the declaration of: double mul = 0; to: double mul =1;
Last edited on
Changing mul 0 to mul 1 worked.

thank you so very much. i cant believe i didnt think of that.
Heh it happens, taking in so much when learning about programming you forget basic things like 5th grade math :P
Topic archived. No new replies allowed.