I am creating a POS system using windows forms for a school project and would like to be able to add decimals together using the code in a button and come up with a total as the output at the end... any ideas on how this can be done?
If following doesn't answer your questions, please edit your post by elaborating your question.
Two questions I get so far.
Generally using List
in C# if data keeps growing.
// Put this as your member variable
List<decimal> m_ItemPriceInOrder = new List<decimal>;
// In your button event
decimal price = ... // Get your price of item
m_ItemPriceInOrder.Add( price );
Using foreach
to iterate through every item in your list.
Also a simple for
loop is okay, but foreach represents "iterating through every item".
decimal sum = 0;
foreach( var item in m_ItemPriceInOrder ){
sum+=item;
}