// Console_Totals-Counts.cpp : main project file. /* ________________________________________________ Learning C++: Lesson 3 Running Totals & Counts Ron Kessler Created 5/25/2016 This little program shows how to keep running totals and counts. _________________________________________________ */ #include "stdafx.h" using namespace System; int main(array ^args) { //---show a message Console::WriteLine("Welcome to Lesson 3: Running Totals & Counts\n\n"); int numItems = 0; //track number of items purchased double totalDue = 0; //track total spent while (true) //this is a loop and lets them order as many things as they want { Console::WriteLine("Enter item to purchase."); String^ thisItem = Console::ReadLine(); numItems += 1; //add 1 to the running count. Same as numItems = numItems + 1 Console::WriteLine("Now enter the price."); double itemPrice = Convert::ToDouble(Console::ReadLine()); //get the price totalDue += itemPrice; //add this price to the running total Console::WriteLine("\n\nPress 1 to add more items. Press 2 to check out."); String^ input = Console::ReadLine(); if (input == "2") break; } //---show output Console::Clear(); Console::WriteLine("Summary of your order\n\n"); Console::Write("You purchased " + numItems + " items today."); Console::WriteLine(" You owe me " + totalDue.ToString("c2")); Console::WriteLine("\n\nPress any key to end."); Console::ReadLine(); return 0; }