Had a moment to sit down and plow through a chapter, and as usual, wound up stuck. My compiler is giving me a string of undefined reference to SALES::[all my function names]
in my main function. It's entirely possible that there are problems within the function definitions, but right now I can't even get the compiler to take a look at them, since my design is somehow failing to call them from main().
// exercise9.4 header file
#ifndef EXERCISE9_4_HEADER_H_INCLUDED
#define EXERCISE9_4_HEADER_H_INCLUDED
namespace SALES
{
const int QUARTERS = 4;
struct Sales
{
double sales[QUARTERS];
double average;
double max;
double min;
};
void setSales(Sales & s, const double ar[], int n); //non-interactive
void setSales(Sales & s); //interactive
void showSales(const Sales & s); //display
}
#endif // EXERCISE9_4_HEADER_H_INCLUDED
// Exercise 9.4 function definitions
#include <iostream>
#include "exercise9.4_header.h"
using namespace std;
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.
The remaining elements of sales, if any, get set to 0. */
void setSales(Sales & s, const double ar[], int n)
{
//stuff, can post if necessary
}
/* gathers sales for 4 quarters interactively, stores them
in the sales member of s, and computes and stores the
average, maximum, and minimum values */
void setSales(Sales & s)
{
// more stuff
}
// display all information in structure s
void showSales(const Sales & s)
{
//display-ish stuff
}
// Exercise 9.4 main function
#include <iostream>
#include "exercise9.4_header.h"
using namespace std;
int main()
{
using namespace SALES;
Sales test;
for (int i = 0; i < QUARTERS; i++)
test.sales[i] = 0;
double testArrayA[QUARTERS] = {0.0, 33.3, 66.7, 100.0};
double testArrayB[QUARTERS] = {25, 75, 0, 0};
setSales(test);
showSales(test);
cout << "Test Array A:\n";
setSales(test, testArrayA, 4);
showSales(test);
cout << "Test Array B:\n";
setSales(test, testArrayB, 2);
showSales(test);
return 0;
}
I'm 9/10 sure I'm just doing something wrong in my main function, but I obviously can't see what it is. Help?