/* --------------------------------------------------------------------------------------------- U S I N G T O T A L S & C O U N T S Ron Kessler C++ 2012 Version --------------------------------------------------------------------------------------------- Notes: This program introduces you to C++ counts & Totals. The program keeps a running total of the amount they spend and the total number of items they bought. The program also shows you how to use module-level or class-level variables Updated 9/30/2015 Removed checkout button to make things simpler. */ #pragma once namespace My2UsingTotalsandCounts { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// /// Summary for Form1 /// public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: Add the constructor code here // } //***********Start of My Code************** //---class or module level variables go here after the InitializeComponent(); stuff // static double grandTotal = 0; //hold the running total // static int numItems = 0; //hold the number of items bought private: System::Void btnAdd_Click(System::Object^ sender, System::EventArgs^ e) { double grandTotal; int numItems; //---take item and cost & put them in textboxes String^ itemSelected = lstItems->Text->Substring(0,15)->Trim(); double price = Convert::ToDouble(lstItems->Text->Substring(16)->Trim()); //---now assign values to the textboxes txtItem->Text = itemSelected->Trim(); txtCost->Text = Convert::ToString(price); //---add this cost to the running total grandTotal += price; numItems++; //same as numItems = numItems + 1 or numItems += 1 lblTotalSpent->Text = "You spent " + grandTotal + " today. Thanks!"; lblNumItems->Text = "You purchased " + numItems + " items."; } private: System::Void btnQuit_Click(System::Object^ sender, System::EventArgs^ e) { this->Close(); } }; }