// Mr. Minich
// CMPSC 101
// Ch. 1 Demo Program #3
// January 30, 2000 // Purpose - to illustrate the dangers of not initializing variables when declaring them

#include <iostream> using namespace std; int main() { const double PA_SALES_TAX = 1.06; // the PA sales tax rate double price = 0.0; // price of a purchase int quantity = 0; // the quantity of items purchased double totalCost; // the total cost of a purchase

// Three variables and one constant are declared above. // price and quantity are initialized but totalCost is not. // Therefore totalCost currently holds a garbage value. It is not automatically // initialized to the value of zero by C++ as you might assume.
cout << "So far the total cost is " << totalCost << endl << endl;
// At this point, totalCost will be displayed as a garbage value. price = 15.99; // assigning price and quantity quantity = 2;

// The statements above are called assignment statements
cout << "The price is $" << price << " each." << endl; cout << "The quantity is " << quantity << "." << endl;
cout << "The total cost, including tax, is $" << totalCost << "." << endl;

return 0; }// end of main