void customerDetails::viewCart()
{
for (int i=0; i<itemDetailsCount; i++)
{
cout<<"\nName - "<<customerDetailsObject[0].itemDetailsObject[i].name<<endl;
cout<<"Rs - "<<customerDetailsObject[0].itemDetailsObject[i].cost<<endl;
cout<<"Sku No - "<<customerDetailsObject[0].itemDetailsObject[i].sku<<endl;
}
[b]cout<<"\nTotal Cost "<<itemDetailsObject[0].cost+itemDetailsObject[1].cost+itemDetailsObject[2].cost<<endl;[/b]
int selection;
cout<<"\n1.Checkout"<<endl;
cout<<"\n2.Back"<<endl;
cin>>selection;
switch (selection)
{
case 1:
categoryDetailsObject.chooseCategory();
break;
case 2:
categoryDetailsObject.displayMusicItemDetails();
break;
default:viewCart();
break;
}
}
this is part of a shopping program which i have written i wanted to calculate the total cost in view cart part so i couldnt figure out how to add the total cost ,there can be any number of items which could be added in add to cart menu btw itemDetailsObject[50] the code which i have blocked is one way but if there are 50 items to be added that method wont be ideal .
the problem is i have to add up the total cost of the items one way is the way which i have added the cost of all the items ..but when there are 30 items costs to be added the method which i have done will be too lengthy .