Jeron1 gave you the answer to your problem. This line :
All[x].Totaldue = (All[i].numTents * 100) + (All[i].numChairs * 15) + (All[i].numSTables * 25) + (All[i].numLTables * 50);
also looks suspect. In fact, all references to All[x] are suspect. If you want to have the totals of each item in an order then you can make an instance of an
order
structure and call it Totals or something like that and sum the quantities of all the
order
items into it.
That brings me to the bigger problem :
x
is a global variable. It is bad enough to have a global variable but to give it a single-letter name makes it even worse. I don't see a need for any of those global variables. The variable
choice
can be local to the
menu
function and returned from it if needed elsewhere.
-edit-
You have
order All[ 15 ]
so add the variable
order Total
. You can sum the totals like this :
for( i = 0; i < numorder; ++i )
{
Total.numTents += All[ n ].numTents;
Total.numChairs += All[ n ].numChairs;
}
You should also make a function to calculate the price of one order, similar to the line of code I noted above. It could like this :
void SetTotalDue( order * porder )
{
porder->Totaldue = ( porder->numTents * 100 );
porder->Totaldue += ( porder->numChairs * 15 );
porder->Totaldue += ( porder->numSTables * 25 );
porder->Totaldue += ( porder->numLTables * 50 );
}
With these, you can call the function for every order and calculate its
TotalDue
. You can also loop through each order and determine the total number of each item ordered as shown above. You can also call the
SetTotalDue
function to get the value of the totals structure like this :
SetTotalDue( & Total );