// Mr. Minich

// CMPSC 101

// Ch. 7 Demo #9

// November 1, 2001

// Purpose - to illustrate the use of flag variables





#include <iostream>

using namespace std;



int main()

{

	int boughtApples = 0;           // flag variable for apple purchase (0 is false)

	int boughtGrapes = 0;           // flag variable for grape purchase (0 is false)

	int menuChoice = 0;             // user's choice from menu

	int numApples = 0;		// number of apples purchased by user

	double currentTotalSpent = 0.0;	// total amount of money spent by user



	while (!boughtApples || !boughtGrapes || menuChoice != 3)

	{

		cout << endl;

		cout << "1 Apples" << endl;

		cout << "2 Grapes" << endl;

		cout << "3 Exit" << endl << endl;

		

		cout << "Enter your menu choice: ";



		// loop iterates until either the user has purchased both apples or grapes or the user exits   

		cin >> menuChoice;               



		if (menuChoice == 1)

		{



			if (!boughtApples)

			{

				cout << "Enter number of apples: ";

				cin >> numApples;



				if (numApples * .5 + currentTotalSpent <= 100)

				{

					currentTotalSpent += numApples * .5;

					// do something appropriate with a flag variable here

				}

				else

				{

					// do something here

				}



			}

			else

			{

				// do something here

			}



		}

		else if (menuChoice == 2)

		{

			// do stuff here

		}

		else if (menuChoice == 3)

		{

			break;				// exiting loop since user chose to exit

		}



        }



        cout << endl << "You owe $" << boughtGrapes * 1.25 + boughtApples * 0.50 << endl;



        return 0;

}// end of main