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.
// 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>
usingnamespace std;
constint MAXYEAR = 10;
constint MAXCOL = 5;
typedefint 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;
}
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;"
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.