// Initializing an array, filling an array and manipulating elements.
//Programmer: dominologi
#include <iostream>
#include <cmath>
usingnamespace std;
#include <iomanip>
int main()
{
constint SIZE_ARRAY = 4;
double myArray [SIZE_ARRAY];
double product = 0.0;
// initialize elements of array to 0
cout<<"\n\t Let's fill the array with decimal values!\n\n";
for (int r = 0; r < SIZE_ARRAY; r++)
// output contents of array in tabular format
{
cout << "Enter array elements "<<r<< ": ";
cin>> myArray[r];
}
// end first for statement
{
cout<<"\n\t The array is now filled as follows...\n\n";
}
// output contents of array in tabular format
cout << "\n\nSubscript" << setw( 13 ) << "Element" << endl;
for ( int o =0; o < 4; o++ )
cout << setw( 5 ) << o << setw( 14 ) << myArray[ o ] << endl;
for ( int b = 0; b < 4; b++ )
{
product = product * myArray [b];
}
cout << "\n\n\tThe product of the array elements is: " << product <<endl;
cout << "\n\n";
system("PAUSE");
return 0;
} // end main
What is your question or problem?
It ran fine for me.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Thanks for the response. It ran fine after I closed it and opened it again. I apologize but, I have no clue as to what you mean by the <>formatting button. Please explain so that I can comply. Thanks in advance...
The initial value of pruduct is 0. As you know from math 0 * anyNumber = 0;
so The product of arrayElement will be 0.
change initial value of product to 1