I am trying to figure out how to make this array work, ive tried endl; and break; in the for loop outside of the four loop and no matter what it wont let me submit past myArray[0]. also the tabular table is not communicating with my array and the product its just not working. i would appreciate any references or any ideas to help me solve it.
Fill the array with decimal values!
Enter array element 0:
Enter array element 1:
Enter array element 2:
Enter array element 3:
The Array is now filled as follow...
subscript Element //depends on number user inputs
0 _
1 _
2 _
3 _
the Product of the array element is:000.000>
//fourdecimal loop array
#include<iostream>
#include<iomanip>
usingnamespace std;
int main()
{
constint SIZE_ARRAY = 5;
int myArray[ SIZE_ARRAY ];
//title
{
cout<<"\n\t Fill The Array with Decimal values.\n\n";
}
// initialize prompt for array [0-4]
for ( int i = 0;i <= SIZE_ARRAY;i++ )
{
cout<<"Enter Array Element"<<i<<":";
cin>> myArray[i];
}
cout<<endl;
//end for
//middle title before the tabular format
{
cout<<"The table is now filled as follow..."<<endl;
}
{
// output contents of array in tabular format
cout << "\n\nSubscript" << setw( 13 ) << "Element" << endl;
for ( int i =0; i < SIZE_ARRAY; i++ )
cout << setw( 5 ) << i << setw( 14 ) << myArray[i] << endl;
}
// attempting to calculate product of array[above]=total
double product = 0.0;
product = myArray[i];
double total= 0.0;
product= total;
cout << fixed << setprecision(3);
cout<< "The Product of the Array elements is:"<<total<<endl;
system("PAUSE");
return 0;
} // end main
//fourdecimal loop array
#include<iostream>
#include<iomanip>
usingnamespace std;
int main()
{
double product = 1.0; //added this variable here
constint SIZE_ARRAY = 5;
int myArray[ SIZE_ARRAY ];
//title
{
cout<<"\n\t Fill The Array with Decimal values.\n\n";
}
// initialize prompt for array [0-4]
for ( int i = 0;i < SIZE_ARRAY;i++ ) //changed this to be just i < SIZE_ARRAY, not i <+ ...
{
cout<<"Enter Array Element"<<i<<":";
cin>> myArray[i];
product *= myArray[i]; //added this line here to calculate the product, I'm guessing this is how you want to calc product.
}
cout<<endl;
//end for
//middle title before the tabular format
{
cout<<"The table is now filled as follow..."<<endl;
}
{
// output contents of array in tabular format
cout << "\n\nSubscript" << setw( 13 ) << "Element" << endl;
for ( int i =0; i < SIZE_ARRAY; i++ )
cout << setw( 5 ) << i << setw( 14 ) << myArray[i] << endl;
}
// None of the commented out code below is needed
// attempting to calculate product of array[above]=total
//double product = 0.0;
//product = myArray[i];
//double total= 0.0;
//product= total;
cout << fixed << setprecision(3);
cout<< "The Product of the Array elements is:"<<product<<endl;
system("PAUSE");
return 0;
} // end main