Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

would someone kindly help me with this c++ homework..I am confused Create a Prog

ID: 3814657 • Letter: W

Question

would someone kindly help me with this c++ homework..I am confused

Create a Program that will calculate the average stock price stored in the prices array. It then should display the average price on the screen. Complete the program using the for statement. Save and run the program.


21. Follow the instructions for starting C++ and viewing the introductory21.cpp file, which is contained in either the Cpp8 Chapliuntroductory21 Project folder or the Cpp8 Chap11 folder. (Depending on your C++ development tool, you may need to open the project/solution file first.) The program should calculate the average stock price stored in the prices array. It then should display the average price screen. Complete the program using the for statement. Save and then run the program.

Explanation / Answer

#include <iostream>

using namespace std;

double calcAvgStockPrice(double prices[], int n)
{
double avg = 0;
for(int i = 0; i < n;i++)
{
avg += prices[i];
}
return avg/n;
}

int main()
{
double prices[] = {5,9.8,5.2,1.3,5.6,7.4};
int n = 6;
cout << "Prices are: ";
for(int i = 0; i < n; i++)
{
cout << prices[i] << " ";
}
cout << endl;


cout << "Avergae stock price is : " << calcAvgStockPrice(prices, n) << endl;
return 0;
}