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
|
#include<iostream>
using namespace std;
void yearTotal(float * sales, int saleSize, float & sum);
void yearAverage(float sum, int saleSize, float & avg);
int main()
{
// 1. here is a typo
//int cout;
int count;
int months;
// 2. use new is ok, but not recommand, you have to free it by yourself
float * sales = nullptr;
// 3. months is uninitialized now, using it is bad!
//sales = new float[months];
float total;
float average;
// 4. typo? it should be std::cout
//count << "Please input the number of monthly sales to be input";
std::cout << "Please input the number of monthly sales to be input";
cin >> months;
sales = new float[months];
for (count = 0; count < months; count++)
{
cout << "Please input the sales for month" << count << endl;
// 5. you need to read from std::cin now
std::cin >> sales[count];
}
// call yearTotal now
//cin >> yearTotal(sales + count)
yearTotal(sales, months, total);
yearAverage(total, months, average);
std::cout << "year total: " << total << std::endl
<< "year average: " << average << std::endl;
return 0;
}
void yearTotal(float * sales, int saleSize, float & sum)
{
}
void yearAverage(float sum, int saleSize, float & avg)
{
}
|