help with arrays problem

Im fairly new in the programming world, and I picked up a problem recently of which I've been struggling with, a lot! This was the starter code.

My question is:

How do I get JUST the arrays working properly...apparently it should be a two parallel 5-element arrays that prompts the user for the number of jars sold.

I have been doing some research about arrays but nothing I try seems to be working, and it has become reallty confusing for me.

Any help, suggestion, hint or idea really would be very appriciated!

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

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

int main() {
    // Constant for the number of salsa types
   

    // Array of salsa types
    string types[NUM_TYPES] = {"mild  ",
                               "medium",
                               "sweet ",
                               "hot   ",
                               "zesty "};

    // Array of sales of each salsa type


    // Total number of jars sold


    // Subscript of the salsa that sold the most.


    // Subscript of the salsa that sold the least.


    // Get the number of jars sold of each type of salsa.


    // Get the number of jars sold.
    cout << "Jars sold last month of "
         << types[type] << ": ";
    cin >> sales[type];

    // Validate the input.

        cout << "Jars sold must be 0 or more. "
             << "Please re-enter: ";
        cin >> sales[type];

	// Get total sales and high and low selling products




	// Display the sales report header.
	cout << endl << endl;
	cout << "     Salsa Sales Report \n\n";
	cout << "Name              Jars Sold \n";
	cout << "____________________________\n";

	// Display the name and jars sold of each type.

		cout << types[salsaType]
			 << setw(21) << sales[salsaType]
			 << endl;


	// Display the total sales, highest seller, and lowest seller.
	cout << "\nTotal Sales:" << setw(15) << totalJarsSold << endl;
	cout << "High Seller: " << types[hiSalesProduct] << endl;
	cout << "Low Seller : " << types[loSalesProduct] << endl;

	return 0;
}
Last edited on
Hello gjur99,

On line 12 you write string types[NUM_TYPES]. But where do you define "NUM_TYPES"?

It looks like you intend to do this on line 9. I would write it as constexpr size_t NUM_TYPES{ 5 };.

Under line 18 you might write int jarsSold[NUM_TYPES]{};. The empty {}s will initialize each element of the array to zero.

There was one very similar to this recently http://www.cplusplus.com/forum/beginner/251355/ that may be of some help.

It is late for me, so I will look at this in the morning.

Hope that helps,

Andy
Topic archived. No new replies allowed.