Not sure why I am getting it, I got this one other time and forgot how i fixed it....
Getting it when i am calling my functions in the main file (3rd)
Three files to this code:
namespace SALES
{
const int QUARTERS = 4;
struct Sales
{
double sales[QUARTERS];
double average;
double max;
double min;
};
// copies the lesser of 4 or n items from the array ar
// to the sales member of s and computes and stores the
// average, maximum, and minimum values of the entered items;
// remaining elements of sales, if any, set to 0
void setSales(Sales & s, const double ar[], int n);
// gathers sales for 4 quarters interactively, stores them
// in the sales member of s and computes and stores the
// average, maximum, and minumum values
void setSales(Sales & s);
// display all information in structure s
void showSales(const Sales & s);
}
// sales.cpp -- definitions of prototypes
#include "stdafx.h"
#include "sales.h"
#include <iostream>
using namespace SALES;
// copies the lesser of 4 or n items from the array ar
// to the sales member of s and computes and stores the
// average, maximum, and minimum values of the entered items;
// remaining elements of sales, if any, set to 0
void setSales(Sales & s, const double ar[], int n)
{
int count = 0;
for (int i = 0; i < n; i++)
{
s.sales[i] = ar[i];
count++;
}
if (count != 4)
{
int remainder = 4 - n;
for (int i = 0; i < remainder; i++)
s.sales[i] = 0;
}
double sum = 0;
for (int i = 0; i < 4; i++)
sum += s.sales[i];
s.average = sum/4;
s.max = s.sales[0];
for (int i = 1; i < 4; i++)
{
if (s.sales[i] > s.max)
s.max = s.sales[i];
}
s.min = s.sales[0];
for (int i = 1; i < 4; i++)
{
if (s.sales[i] < s.min)
s.min = s.sales[i];
}
}
// gathers sales for 4 quarters interactively, stores them
// in the sales member of s and computes and stores the
// average, maximum, and minumum values
void setSales(Sales & s)
{
for (int i = 0; i < 4; i++)
{
std::cout << "Please input a sales #: ";
std::cin >> s.sales[i];
}
double sum = 0;
for (int i = 0; i < 4; i++)
sum += s.sales[i];
s.average = sum/4;
s.max = s.sales[0];
for (int i = 1; i < 4; i++)
{
if (s.sales[i] > s.max)
s.max = s.sales[i];
}
s.min = s.sales[0];
for (int i = 1; i < 4; i++)
{
if (s.sales[i] < s.min)
s.min = s.sales[i];
}
}
// display all information in structure s
void showSales(const Sales & s)
{
std::cout << "Sales numbers are " << s.sales[0] << ", " << s.sales[1] << ", " << s.sales[2] << ", " << s.sales[3] << std::endl;
std::cout << "Average: " << s.average << std::endl;
std::cout << "Max: " << s.max << std::endl;
std::cout << "Min: " << s.min << std::endl;
}
// Exc_4.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "sales.h"
#include <iostream>
using namespace SALES;
int _tmain(int argc, _TCHAR* argv[])
{
double numbers[3] = {4.5, 2.3, 4.2};
Sales test;
setSales(test, numbers, 3);
showSales(test);
Sales test2;
setSales(test2);
showSales(test2);
system("PAUSE");
return 0;
}