Function problems

I've been at this for a couple hours and i know i'm making some pretty stupid mistakes. My brain feels numb i've been dinking around with this for so long. I'm having trouble with how to enter the sales information in. I got the other crap to print just fine. I'm just bypassing crucial code that should be computing the sales value's with the months but I don't know how to do it.

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
 // This program will read in the quarterly sales transactions for a given number
// of years. It will print the year and transactions in a table format.
// It will calculate year and quarter total transactions.


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

const int MAXYEAR = 10;
const int MAXCOL = 5;

typedef int SalesType[MAXYEAR][MAXCOL];   // creates a new 2D integer data type

void   getSales(SalesType, int&);		  // places sales figures into the array
void   printSales(SalesType, int);        // prints data as a table
void   printTableHeading();               // prints table heading


int main()

{
	int yearsUsed;                        // holds the number of years used

	SalesType sales;                      // 2D array holding
	                                      // the sales transactions


	getSales(sales, yearsUsed);           // calls getSales to put data in array
	printTableHeading();				  // calls procedure to print the heading
	printSales(sales, yearsUsed);         // calls printSales to display table

	return 0;
}


//*****************************************************************************
//                           printTableHeading
//
//  task:     This procedure prints the table heading
//  data in:  none
//  data out: none
//
//*****************************************************************************


void printTableHeading()

{
	cout << setw(30) << "YEARLY QUARTERLY SALES" << endl << endl << endl;

	cout << setw(10) << "YEAR" << setw(10) << "Quarter 1"
	 	 << setw(10) << "Quarter 2" << setw(10) << "Quarter 3"
		 << setw(10) << "Quarter 4" << endl;
}



//*****************************************************************************
//                           getSales
//
//  task:     This procedure asks the user to input the number of years.
//			  For each of those years it asks the user to input the year
//            (e.g. 2004), followed by the sales figures for each of the
//            4 quarters of that year.  That data is placed in a 2D array
//  data in:  a 2D array of integers
//  data out: the total number of years
//
//*****************************************************************************

void getSales(SalesType  table, int&  numOfYears)
{

	cout << "Please input the number of years (1-" << MAXYEAR << ')' << endl;
	cin >> numOfYears;


	// read and store the next value
	cout << "Enter the sales" << endl;
	cin >> sales;

}


//*****************************************************************************
//                           printSales
//
//  task:     This procedure prints out the information in the array
//  data in:  an array containing sales information
//  data out: none
//
//*****************************************************************************



void printSales(SalesType table, int numOfYears)
{
	//print the table
	cout << table << " " << printSales << endl;

}
Have you tried using a debugger to step through the code and observe the program's behavior?
no, it's not that i can't find the error per say so much as I know that i'm brainfarting on a loop inside the function.
Looking at getSales(), I see you have two parameters declared. What are they for?
void getSales(SalesType table, int& numOfYears)

What i'm trying to do, or what I think i'm trying to do rather, is have the number of years and table I guess I took from a different example where I used it in this working function (below) - I just turned in the assignment, so i'm going to fail it no matter what but I'd still like to learn what I should already know at this point. I know enough to know how wrong it is and typically where it's wrong, but i'm really having a difficult time with this.

"void printPrices(PriceType table, int numOfRows, int numOfCols){
cout << fixed << showpoint << setprecision(2);

for (int row = 0; row < numOfRows; row++){
for (int col = 0; col < numOfCols; col++)
// Fill in the code to print the table
cout << setw(4) << table[row][col] << " ";
cout << endl;"
To elaborate, I'm not asking for the code - any slow but effective advice pointing me in the right direction in the long run is desired at this point.
So as I see it you are trying to use that function to read in data from the user into an array.

I think you may have meant to try to read into the array you passed, rather than the undeclared variable 'sales'. However, as you may notice cannot cin>> into an array just like that. Similar to your example of printing out the array, you will need loops to go through each element of the array and read data into that spot.
Topic archived. No new replies allowed.