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?