passing Struct Arrays between functions

For a program I have to pass a struct within an array to the main function and then to another function that will display it, but the numbers and strings don't come out right.

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
int main()
{
	Order Order1;
	Order orderList[NumOrder];								


	for (int i = 0; i < NumOrder; i++)
	{
		orderList[i];												


		cout << "Enter information for order #" << i + 1 << ": " << endl;
		GetOrder();										
		cin.ignore(1000, '\n');
		cout << endl;
		ProcessOrder(orderList[i]);							
																
	}
	DisplayOrders(orderList);
	

	system("pause");
	return 0;
} 
 void ProcessOrder(Order & myOrder)
{
	myOrder.totalprice = (myOrder.unitprice*myOrder.quantity) + (myOrder.unitprice*myOrder.quantity*0.07);
							
	Order orderList = myOrder;
}

void DisplayOrders(Order orderList[])
{
	int counter;
	cout << "Here are your orders." << endl;      
	cout << "----------------------------" << endl;
	for (counter = 0; counter < 3; counter++)
	{
		cout << "Order #" << counter+1 << endl; 
		cout << "Item Name: " << orderList[counter].name << endl;
		cout << setprecision(2) << orderList[counter].totalprice;
		cout << "Unit Price: $" << orderList[counter].unitprice << endl;
		cout << "Quantity: " << orderList[counter].quantity << endl;
		cout << "Total Price: $" << orderList[counter].totalprice << endl; 
		cout << "" << endl;
	}

}
Last edited on
closed account (48T7M4Gy)
but the numbers and strings don't come out right
Are you going to show us what is happening or is this a mystery tour?

In the absence of an answer to that question and in the absence of a sensible test program - one that shows what your struct is and doesn't require the tester to input data and therefore not concentrate on the real issue, your best bet is to revise passing arrays to functions (not main() BTW ) in a tutorial like this one:
http://www.cplusplus.com/doc/tutorial/arrays/
Topic archived. No new replies allowed.