Write a program that will read monthly sales into a dynamically allocatedarray.
ID: 3618728 • Letter: W
Question
Writea program that will read monthly sales into a dynamically allocatedarray. The
program will input the size of the array from the user. Itwill call a function that will find the
yearly sum (the sum of all the sales). It will also call anotherfunction that
will find the average.
What I have:
#include "stdafx.h"
#include<iostream>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
float* sales;
int count;
int clrscr;
float yearlySum()
{
float sum = 0.0;
for(int i=0;i<count;i++)
{
sum = sum +sales[i];
}
return sum;
}
float average()
{
return yearlySum()/(count+1);;
}
void printSource()
{
clrscr();
cout << " Elements in the sourcearray : "<<endl;
for(int i=0;i<count;i++)
{
printf("%.2f ",sales[i]);
}
cout<<" "<<endl;
}
int main()
{
char yesno = 'n';
count = 0;
do
{
cout << " Entersales for a month :"<<endl;
cin>>sales[count]>>endl;
count++;
cout << " Do youwant to enter another ID number(Y/N) : "<<endl;
cin>>yesno>>endl;
}while(yesno == 'y' || yesno == 'Y');
printSource();
printf(" Yearly Sum of sales :%.2f",yearlySum());
printf(" Avearge sales :%.2f",average());
return 0;
}