1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <string>
double high_sales(char [],double);
double low_sales(char[],double);
double average_sales(char[],double);
double get_data(char[]);
using namespace std;
const int SIZE=12;
const int LNGTH=20;
char Finish_Month[LNGTH]="";
void main()
{
double sales=0.0;
char month[SIZE][LNGTH]={{"January"},{ "Febuary"},{ "March" },{"April"},{ "May" },{"June"},{ "July"},{ "August"},{ "September" },{"October"},{ "November"},{ "December"}};
double msales[SIZE];
double hsales=0.0;
double lsales=0.0;
double avg_sales=0.0;
for(int count=0; count<SIZE;count++)
{
msales[count]=get_data(month[count]);
hsales=high_sales(month[count],msales[count]);
lsales=low_sales(month[count],msales[count]);
avg_sales=average_sales(month[count],msales[count]);
}
cout<<" The highest sales were in "<< Finish_Month<<" with "<<"$"<<hsales<<endl;
cout<<" The lowest sales were in "<< Finish_Month<<" with "<<"$"<<lsales<<endl;
cout<<" Average Sales is "<<" "<<avg_sales<<endl;
return;
}
double get_data(char month[])
{
double sales;
cout<<"Please enter sales for "<<" "<<month<<": ";
cin>>sales;
return sales;
}
double high_sales(char month[],double sales)
{
static double hsales=0.0;
if(sales>hsales)
{
hsales=sales;
}
strcpy_s(Finish_Month,month);
return hsales;
}
double low_sales(char month[],double sales)
{
static double lsales=1000000000.0;
if(sales<lsales)
{
lsales=sales;
}
strcpy_s(Finish_Month,month);
return lsales;
}
double average_sales(char month[],double sales)
{
static double avg_sales=0.0;
static double total_sales=0.0;
total_sales=total_sales+sales;
avg_sales=total_sales/SIZE;
return avg_sales;
}
|