Hey all. I'm trying to get the FindDaysOver function to grab the avg result from the CalcAvg function result in main. What am I doing wrong? Any help would be appreciated!

``````#include<iostream>
#include <iomanip>
using namespace std;

double FindMax(double [], int);
double FindMin(double [], int);
double CalcAvg(double [], int);
int FindDaysOver(double [], int, double avg);

int main()
{
const int NUMELS = 20;
const int NUMELS3 = 8;

double stock1[] = {34.25,40.50,36.50,40.00,
30.25,30.25,35.50,36.00,
34.25,37.00,34.00,35.00,
36.25,34.25,40.50,41.50,
41.50,40.00,36.50,34.50};

double stock2[] = {40.25,38.50,34.50,33.50,
30.50,29.75,37.50,36.00,
34.75,38.00,34.25,37.00,
34.25,37.50,34.50,38.50,
37.50,37.25,38.25,37.50};

double stock3[] = {100.41, 90.45, 99.30, 102.99,
98.54, 95.30, 92.32, 110.88};

double avg, max, min ;
int days;

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout << setw(41) << "The Stock Problem" << endl;
cout << setw (49) << "__________________________________" << endl << endl;
//Report One
cout << setw (48) << "Report One - Maximums & Minimums" << endl <<endl;
cout << setw (37) << "Stock One:" << endl;

max = FindMax(stock1, NUMELS);
cout << setw (31) << "Max:" << " " << max << endl;

min = FindMin(stock1, NUMELS);
cout << setw (31) << "Min:" << " " << min << endl << endl;

cout << setw (37) << "Stock Two:" << endl;

max = FindMax(stock2, NUMELS);
cout << setw (31) << "Max:" << " " << max << endl;

min = FindMin(stock2, NUMELS);
cout << setw (31) << "Min:" << " " << min << endl << endl;

system( "PAUSE" );

//Report Two
cout << "\n         Report Two - Averages & Days Exceeding Average" << endl << endl;
cout << setw (37) << "Stock One:" << endl;

avg = CalcAvg(stock1, NUMELS);
cout << setw (35) << "Average:" << " " << avg << endl;

days = FindDaysOver (stock1, NUMELS, avg);
cout << setw (42) << "Number of Days:" << " " << days << endl << endl;

cout << setw (37) << "Stock Two:" << endl;

avg = CalcAvg(stock2, NUMELS);
cout << setw (35) << "Average:" << " " << avg << endl;

days = FindDaysOver (stock2, NUMELS, avg);
cout << setw (42) << "Number of Days:" << " " << days << endl << endl;

system( "PAUSE" );

//Report Three
cout << "\n         Report Three - Stock Three: Maximum & Average" << endl << endl;

max = FindMax(stock3, NUMELS3);
cout << setw (31) << "Max:" << "    " << max << endl;

avg = CalcAvg(stock3, NUMELS3);
cout << setw (35) << "Average:" << " " << avg << endl << endl;

return 0;
}

double FindMax(double array[], int size)
{
double max = 0;

for(int index = 0; index < size; index++)
{
if (array[index] > max)
max = array [index];
}
return (max);
}

double FindMin(double array[], int size)
{
double min = array [0];

for(int index = 0; index < size; index++)
{
if (array[index] < min)
min = array [index];
}
return (min);
}

double CalcAvg(double array[], int size)
{
double sum = 0;

for(int index = 0; index < size; index++)
{
sum = sum + array[index];
}
return (sum /size);
}

int FindDaysOver(double array[],int size, double avg)
{

int days = 0;

for (int index = 0; index < size; index++)
{
if (array[index] > avg)

days =days++;
}
return (days);
}``````
2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by WaltP

Reformat using this link and repost.

Edited by WaltP: n/a

Is the following easier to read?

``````#include<iostream>
#include <iomanip>
using namespace std;

double FindMax(double [], int);
double FindMin(double [], int);
double CalcAvg(double [], int);
int FindDaysOver(double [], int, double avg);

int main()
{
const int NUMELS = 20;
const int NUMELS3 = 8;

double stock1[] = {34.25,40.50,36.50,40.00,
30.25,30.25,35.50,36.00,
34.25,37.00,34.00,35.00,
36.25,34.25,40.50,41.50,
41.50,40.00,36.50,34.50};

double stock2[] = {40.25,38.50,34.50,33.50,
30.50,29.75,37.50,36.00,
34.75,38.00,34.25,37.00,
34.25,37.50,34.50,38.50,
37.50,37.25,38.25,37.50};

double stock3[] = {100.41, 90.45, 99.30, 102.99,
98.54, 95.30, 92.32, 110.88};

double avg, max, min ;
int days;

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout << setw(41) << "The Stock Problem" << endl;
cout << setw (49) << "__________________________________" << endl << endl;

//Report One

cout << setw (48) << "Report One - Maximums & Minimums" << endl <<endl;
cout << setw (37) << "Stock One:" << endl;

max = FindMax(stock1, NUMELS);
cout << setw (31) << "Max:" << " " << max << endl;

min = FindMin(stock1, NUMELS);
cout << setw (31) << "Min:" << " " << min << endl << endl;

cout << setw (37) << "Stock Two:" << endl;

max = FindMax(stock2, NUMELS);
cout << setw (31) << "Max:" << " " << max << endl;

min = FindMin(stock2, NUMELS);
cout << setw (31) << "Min:" << " " << min << endl << endl;

system( "PAUSE" );

//Report Two

cout << "\n         Report Two - Averages & Days Exceeding Average" << endl << endl;
cout << setw (37) << "Stock One:" << endl;

avg = CalcAvg(stock1, NUMELS);
cout << setw (35) << "Average:" << " " << avg << endl;

days = FindDaysOver (stock1, NUMELS, avg);
cout << setw (42) << "Number of Days:" << " " << days << endl << endl;

cout << setw (37) << "Stock Two:" << endl;

avg = CalcAvg(stock2, NUMELS);
cout << setw (35) << "Average:" << " " << avg << endl;

days = FindDaysOver (stock2, NUMELS, avg);
cout << setw (42) << "Number of Days:" << " " << days << endl << endl;

system( "PAUSE" );

//Report Three

cout << "\n         Report Three - Stock Three: Maximum & Average" << endl << endl;

max = FindMax(stock3, NUMELS3);
cout << setw (31) << "Max:" << "    " << max << endl;

avg = CalcAvg(stock3, NUMELS3);
cout << setw (35) << "Average:" << " " << avg << endl << endl;

return 0;

}

double FindMax(double array[], int size)
{
double max = 0;

for(int index = 0; index < size; index++)
{
if (array[index] > max)
max = array [index];
}
return (max);
}

double FindMin(double array[], int size)
{
double min = array [0];

for(int index = 0; index < size; index++)
{
if (array[index] < min)
min = array [index];
}
return (min);
}

double CalcAvg(double array[], int size)
{
double sum = 0;

for(int index = 0; index < size; index++)
{
sum = sum + array[index];
}
return (sum /size);
}

int FindDaysOver(double array[],int size, double avg)
{

int days = 0;

for (int index = 0; index < size; index++)
{
if (array[index] > avg)

days =days + 1;
}
return (days);
}``````

Is the following easier to read?

Much!!

Hey all. I'm trying to get the FindDaysOver function to grab the avg result from the CalcAvg function result in main. What am I doing wrong?

Nothing that I can see.

Much!!

Nothing that I can see.

Cool! I used the online compiler at code pad and received a system fork error. I wasn't sure if it was the compiler or my code. I can't wait to get off work and run it at home! I'll post if I'm successful. Is it possible to keep this thread open til then?