// Mr. Minich
// CMPSC 201
// Ch. 2 Demo Program #2
// 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 = 0.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 << endl; cout << "The quantity is " << quantity << endl; cout << "The PA sales tax rate is " << PA_SALES_TAX << endl << endl;
cout << "Now the total cost is " << totalCost << endl;
return 0; }// end of main