// Native_TotalsAndCounts.cpp : Defines the entry point for the console application. /* ________________________________________________ Learning C++: Lesson 3 Running Totals & Counts Ron Kessler Created 12/29/2016 Native Version This little program shows how to keep running totals and counts. Run using CTL-F5 _________________________________________________ */ #include "stdafx.h" #include #include using namespace std; int main () { //---show a message cout << "Welcome to Lesson 3: Running Totals & Counts\n\n"; //---define variable string whichProduct; int numItems = 0; //track number of items purchased double itemPrice = 0; double totalDue = 0; //track total spent while (true) //this is a loop and lets them order as many things as they want { cout << "Enter item to purchase: "; getline(cin, whichProduct); numItems += 1; //add 1 to the running count. Same as numItems = numItems + 1 cout << "Now enter the price: "; cin >> itemPrice; //get the price cin.ignore (); totalDue += itemPrice; //add this price to the running total cout << "\n\nPress 1 to add more items. Press 2 to check out."; string input; cin >> input; cin.ignore (); if (input == "2") break; system ("cls"); } //---show output system ("cls"); //clear screen cout.precision (2); cout << "*********Summary of your order*********\n\n"; cout << "You purchased " << numItems << " items today."; cout << " You owe me $" << fixed << totalDue << "\n\n"; return 0; }