In: Computer Science
Must be written in c++
Must display comments
Write a program that will read monthly sales into a dynamically allocated array allocated array of double values.
Your program should:
- prompt the user to enter the size of the array ( that is the
number of monthly sales)
- dynamically allocate an array large enough to hold the number of
monthly sales given
by the user
- find and print the yearly sum of all the monthly sales
Note: don’t forget to deallocate memory!
Sample Run:
Enter the number of monthly sales to be input: 4
Enter the monthly sales for month 1: 1290.89
Enter the monthly sales for month 2: 905.95
Enter the monthly sales for month 3: 1567.98
Enter the monthly sales for month 4: 994.83
The total sales for the year is: $4759.65
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
#include<iostream>
using namespace std;
//sutting up prototypes
double findYearlySum(double sales[],int n);
//main function
int main()
{
//declaration
double *sales;
int arraysize;
cout<<"Enter the number of monthly sales to be input: ";
cin>>arraysize;
//dynamic creation of array
sales=new double[arraysize];
cout<<"Enter Monthly Sales"<<endl;
//reading monthly sales
for(int i=0;i<arraysize;i++)
{
cout<<"Enter the monthly sales for month
"<<(i+1)<<": ";
cin>>sales[i];
}
//calling yearly sum function
double sum=findYearlySum(sales,arraysize);
//calling average function
//display result
cout<<"The total sales for the year is: $"<<sum<<endl;
delete sales
;
}//end of main
//function definition for finding sum
double findYearlySum(double *sales,int n)
{
double sum=0;
for(int i=0;i<n;i++)
sum +=sales[i];
return(sum);
}

Kindly revert for any queries
Thanks.