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.
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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.