Create an array of 20 doubles Assign values to your array us
Solution
Please find the required program along with its output. Please see the comments against each line to understand the step.
#include <iostream>
#include <string>
using namespace std;
int main()
{
double myDoubles[20]; //declare the double array
for(int i = 0; i < 20; i++){ //assign values to the double array
myDoubles[i] = i;
}
cout << \"Array values are: \" << endl;
for(int i = 0; i < 20; i++){ //print the values of array
cout << myDoubles[i] << \" \" << flush;
}
cout <<endl;
double avg = 0;
for(int i = 0; i < 20; i++){ //iterate through the loop to determine the average
avg = avg + myDoubles[i];
}
avg = avg/20;
cout << \"The average value of myDoubles is: \" << avg <<endl; //print the average
}
-------------------------------------------------------------------------------------------
OUTPUT:
Array values are:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
The average value of myDoubles is: 9.5
