Help With this Sales Project

Hi Everyone, I am super new to C++ and we are getting into arrays in class and it is really stressing me out... I need to fill in the blanks in this program and was wondering if anyone could help me with it because I really don't get the whole arrays thing. my assignment is posted below. Any help is appreciated thank you!



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
// 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.

// Michael Orlando
// Week 10 Lab 2

#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;

	// Fill in the code to read and store the next value
}

//*****************************************************************************
//	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)
{
	// Fill in the code to print the table
}
Last edited on
PLEASE learn to use code tags, it makes reading and commenting on your code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/

HINT: You can edit your post and add the tags.
Okay I figured that out and fixed it! Thank You!
Still looking for help on this project tho! I'm not even sure if coding is for me at this point but I need to pass the class and i'm stressed! Half the work is done already I just have no clue where to even start filling in those blanks :(
Last edited on
http://www.cplusplus.com/doc/tutorial/arrays/


Orlando1130 wrote:
Half the work is done already

Hmmm!
Last edited on
Don't stress. Arrays are very hard for new programmers to understand. Once you get it though, you'll realize that they're extremely useful.

I think part of the difficulty you're having is that the assignment jumps right into 2 dimensional arrays. Ouch.

Let's take a step back. Can you write a program that will read 5 numbers from the user and then print them back out? Here is a skeleton of the code. Hint: use for loops to read and write 5 numbers.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main()
{
    int numbers[5];             // an array of 5 numbers

    cout << "Please enter 5 numbers: " << endl;

    // ENTER CODE HERE TO READ THE 5 NUMBERS

    cout << "Your numbers are: " << endl;

    // ENTER CODE HERE TO PRINT OUT THE 5 NUMBERS
}


Once you can write this program and understand it, I think you'll be able to do the assignment pretty easily.
This is what I have, although I think I am way off... any chance anyone can help me make this right? It would be much appreciated because my project is already late past due. Here is something you can work with to help me thank you in advance!

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
102
103
104
105
106
107
108
109
110
111
112
// 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.

// Michael Orlando
// Week 10 Labs Sales Chart

#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;


}

//*****************************************************************************
//	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)
{


    double salesQ1;
    double salesQ2;
    double salesQ3;
    double salesQ4;
    int i = 0;

    for (i = 0; i < numOfYears; i++)
    {

    cout << "What were the sales numbers for Quarter 1?";
    cin  >> salesQ1;

    cout << "What were the sales numbers for Quarter 2?";
    cin  >> salesQ2;

    cout << "What were the sales numbers for Quarter 3?";
    cin  >> salesQ3;

    cout << "What were the sales numbers for Quarter 4?";
    cin  >> salesQ4;


    cout << setw(10) << salesQ1 << setw(10) << salesQ2 << setw(10) << salesQ3 << setw(10) << salesQ4 << endl;


}

}

Last edited on
UPDATE GUYS:

I FINALLY GOT IT TO RUN AND EVERYTHING LOOKS GOOD!
(with a little help from my friend)
The only problem is, i'm getting gibberish output on my chart :( I am assuming people will be more keen to help with it now that I am 99 percent done, but must have a mistake somewhere because of the gibberish output in my chart. My finished code is down below. Again, what I am asking for at this point is simply where there would be an issue (not an error persay, the code runs fine) but an issue where I would get a bunch of random numbers in my chart as opposed to the chart tracking the sales numbers and outputting them properly.


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
102
103
104
105
// 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.

// Michael Orlando
// Week 10 Labs Sales Chart

#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;

	for (int i = 0; i < numOfYears; i++)
    {
        cout << "Please input the year number: ";
        cin  >> table[i][0];

        for (int q = 1; q < 5; q++)
        {
            cout << "Please input the number of transactions for Quarter number " << q << " of year " << table[i][0] << endl;
            cin  >> table [i][q];

        }
    }


}

//*****************************************************************************
//	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)
{
   for (int i = 0; i < numOfYears; i++)
   {
       cout << setw(10) << table[i][0] << setw(10) << table[i][1] << setw(10) << table[i][2] << setw(10) << table[i][3] << setw(10) << table[i][4] << endl;
   }

   }




Orlando1130 wrote:
EVERYTHING LOOKS GOOD!
Orlando1130 wrote:
the code runs fine
Orlando1130 wrote:
but must have a mistake somewhere because of the gibberish output

Quite.



OK, run it in c++ shell (little gear-wheel icon to the top right of your code sample).
Compile or run it and look at the warning for line 26.

Do you know the difference between "passing by reference" and "passing by value"?
You are doing the latter. You want to do the former (for numOfYears).



// It will calculate year and quarter total transactions.

That is missing.
Last edited on
... now that I am 99 percent done ...


I admire your optimism.

As you gain programming experience you will learn that just because 99% of your code is correctly written, it does not follow that you are 99% done. Often, tracking down the bugs in the final 1% of the code can take longer than writing the initial code in the first place.

Tracking down bugs in your code and fixing them can be frustrating and time consuming. I have had sleepless nights as I lie awake at night going over problems in my code when I should be sleeping.

But when you find the problem and fix it, the feeling of accomplishment and satisfaction is tremendous! It's frequently what keeps me going in the programming field.

This is not meant to be a criticism of your viewpoint, but to encourage you to see the bigger programming picture. Tracking down the bugs is a major part of programming--learn to love it.
Topic archived. No new replies allowed.