Parallel One-Dimensional Arrays

Alright, so I'm having trouble with another program. According to the problem, I need to create a program that will display three columns, each displaying the minimum order amounts, the maximum order amounts and the shipping fee for each order size range. After the user enters the number of items they've ordered/their order size, the program is supposed to show both the chart and appropriate shipping fee for the customer's order. So far, I have a program that will allow the user to insert their order size/ the number of items ordered, but it also asks the user to enter the individual numbers for each column. A friend told me that I need to create another file that will allow the chart to be hard-wired into the program, but I'm pretty sure that's supposed to be for a worst case scenario. Please help as soon as you can, your guidance is greatly needed.

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
  #include <iostream>
using namespace std;

int orderShip[4] = { 15, 10, 5, 0 };

int main()
{
	//declare variables and array
	int orderSize = 0;
	int orderMin[4] = { 1, 11, 51, 101 };
	int orderMax[4] = { 10, 50, 100, 99999 };
	int orderShip[4] = { 15, 10, 5, 0 };

		//enter order size
	cout << "Enter how many items you ordered:" << endl;
	cin >> orderSize;
		
	//display the three lists
	cout << "Minimum Order Amount:" << orderMin << endl;
	cout << "Maximum Order Amount:" << orderMax << endl;
	cout << "Order Shipping Cost:" <<orderShip<< endl;

		//display the arrays' contents
		cout << endl;
		for (int x = 0; x < 4; x++)
		{
			cout << "Order shipping fee:" << orderSize += orderShip[x];
		}//end for

	system("pause");
	return 0;
}//end of main function 
The actual requirements (computations required) are unclear to me.
You input orderSize but never use that value?
To display lists you need to place them in a loop.
As far as I know this line,
cout << "Minimum Order Amount:" << orderMin << endl;
is simply printing the address of the first item in that list.

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
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
#include <iomanip>   // used to set width between columns
using std::setw;

int main()
{
    //declare variables and array
    int orderSize = 0 ;
    int orderMin[4] = { 1, 11, 51, 101 };
    int orderMax[4] = { 10, 50, 100, 99999 };
    int orderShip[4] = { 15, 10, 5, 0 };

    //enter order size
    cout << "Enter how many items you ordered:" << endl;
    cin >> orderSize;

    //display the three lists
    cout << setw(3) << "order min" << setw(13) << "order max" << setw(26) << "ordership" << endl;
    for (int i=0; i<4; i++)
    {
        cout << setw(3) << orderMin[i] << setw(13) << orderMax[i] << setw(26) << orderShip[i] << endl;
    }

    return 0;
}//end of main function 

Last edited on
This works incredibly well, now I am only having trouble with getting the program to respond to the user with the price that matches however many items (s)he has ordered. Here is what I have so far:
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
//beginning of CodeWriter's code
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
#include <iomanip>
using std::setw;

int main()
{
	//declare variables and array
	int orderSize = 0;
	int orderMin[4] = { 1, 11, 51, 101 };
	int orderMax[4] = { 10, 50, 100, 99999 };
	int orderShip[4] = { 15, 10, 5, 0 };

	//enter order size
	cout << "Enter how many items you ordered:" << endl;
	cin >> orderSize;

	//display the three lists
	cout << setw(3) << "order min" << setw(13) << "order max" << setw(26) << "ordership" << endl;
	for (int i = 0; i<4; i++)
	{
		cout << setw(3) << orderMin[i] << setw(13) << orderMax[i] << setw(26) << orderShip[i] << endl;
	}
//end of CodeWriter's code
	//display the appropriate price
	if (orderSize >= 1 && orderSize <= 10)
	{
		cout << "Shipping Price: $15.00" << endl;
	}
	else if (orderSize >= 11 && orderSize <= 50)
	{
		cout << "Shipping Price: $10.00" << endl;
	}
	else if (orderSize >= 51 && orderSize <= 100)
	{
		cout << "Shipping Price: $5.00" << endl;
	}
	else(orderSize >= 101 && orderSize <= 99999)
	{
		cout << "No Shipping Fee." << endl;
	}
	//end if/else
	system("pause");
	return 0;
}//end of main function  

Last edited on
No code tags this time?

Andy
Thanks for noticing. I apologize.
You could go back and edit your post!?

Andy
Is that what you meant? I just "watermarked" CodeWriter's work last time.
Yep -- so much more readable!

I was going to mention that you if-else-if chain is a bit more complicated than necessary, if you think about how the upper bound of the preceding if() interacts with the lower bound of the current one.

But given your arrays orderMin and orderMax, shouldn't you be using a loop instead of the it-else-if chain?? Then you'll be future proofed against adding more ranges.

Andy
Topic archived. No new replies allowed.