This project is a little more complex than the previous projects I have posted. The grocery store counter is an application modeled after the manual coin counters that grocery stores previously used to balance the register. The user is able to enter amounts in cents based on the revenue they are receiving. This counter works up to $99.99.

That is the limit each register is able to carry safely in stores. Once that amount is reached, an overflow message is given to the user to reset the program. In a real world setting, that amount would have the cashier place their extra balance into the store safe. This provides safe keeping in case the store would be robbed. It is generally safer to have small amounts of cash in the register.

For user input, the application is able to take four different values. The first value is for cents. The second value is for dimes. The third value is for dollars. The fourth value is for ten dollars amounts. It is generally best practice to start entering larger values into the system. The user would start with ten dollar amounts and then work down through dollars, dimes, and finally cents. This is not a hard rule. The user can actually enter the amounts in any order.

The program is written in the C++ programming language. All of the functions are included in the main cpp file. There is also a compiled .exe file that can be executed to test the application.

Introduction

This counter allows you to increase the variables for money up to $99.99. Once the limit is reached an overflow alert appears telling the user to restart the program.

How to run

Included is the main.cpp file of the program.  Load the file into any C++ complier to build and run the program.  There is also an executable that has already been compiled for the Windows operating system.

/*
* Grocery Store Counter created by Richie Leahey.
*
* This counter allows you to increase the varables for money up to $99.99.
* Once the limit is reached an overflow alert appears telling the user to restart the program.
*/

#include <iostream>
#include <cstdlib>

using namespace std;

class Counter { // public and private variables
public:
	Counter();
	void reset();
	void incr1();
	void incr10();
	void incr100();
	void incr1000();
	void displaycents();
	void displaydimes();
	void displaydollars();
	void displaytendollars();
	int currentCount();
	void display();
	bool overflow();
	void title();

private:
	int cents;
	int dimes;
	int dollars;
	int tendollars;
	bool overflowFlag;
};

void title() {  // Prints the title at the beginning of the program.
	cout << "Grocery Store Counter";
	cout << endl;
}

int main() {

	title();
	cout << endl;

	int i; // i stands for the integer amount for each place value
	int x; // x is used to check if the input is between 1-9
	char z; // z is the variable that checks the user input and decides what should happen
	Counter c; // counter is represented by c, so each counter input would be c.input
	int y = 100; // sets the over flow at 100 
	while (y-- > 0) {
		if (c.overflow())
			cout << "Overflow - Please Restart" << endl;

		c.displaytendollars(); c.displaydollars(); // displays options for user input
		cout << "."; // adds the decimal in the dollar amount between the dollars and dimes
		c.displaydimes(); c.displaycents();
		cout << endl << endl << endl;
		cout << "Enter one of the characters found below followed by an integer (1-9):";
		cout << endl;
		cout << endl;
		cout << "a for cents\n";
		cout << "s for dimes\n";
		cout << "d for dollars\n";
		cout << "f for ten dollars\n";
		cout << endl;
		cout << "o to check overflow\n" << endl << endl;
		cout << "q to quit.\n" << endl;
		cin >> z;

		if (z != 'a' && z != 's' && z != 'd' && z != 'f') {  // if statement seeing if user wants to test for overflow and makes sure the user inputs a valid character
			if (z == 'Q' || z == 'q') {
				cout << z << " pressed.  Quitting\n";
				return 0;
			}

			if (z == 'o') {
				cout << "Overflow test requested\n";
				if (c.overflow()) {
					cout << "Overflow - Please Restart" << endl;
				}
				else {
					cout << "No overflow, please continue" << endl;
				}
				continue;
			}
			cout << "Character Not Found";
		}

		cin >> x;
		if (!(0 < x && x <= 9)) { //checks to see if integer is between 1 and 9
			cout << endl;
			cout << "Digit must be between 1 and 9\n";
			cout << endl;
			continue;
		}

		switch (z) { // switch statement that increments the place value based on user input - a=cents - s=dimes - d=dollars - f=tendollars
		case 'a': for (i = 0; i < x; i++)
			c.incr1();
			cout << endl << endl;
			break;
		case 's': for (i = 0; i < x; i++)
			c.incr10();
			cout << endl << endl;
			break;
		case 'd': for (i = 0; i < x; i++)
			c.incr100();
			cout << endl << endl;
			break;
		case 'f': for (i = 0; i < x; i++)
			c.incr1000();
			cout << endl << endl;
			break;
		case 'Q' || 'q': cout << "Quitting\n";
			return 0;
		default: cout << endl << " " << endl;
		}
	}

	system("pause");

	return 0;
}


void Counter::displaycents() { // makes private integer public
	cout << cents;
}

void Counter::displaydimes() { // makes private integer public
	cout << dimes;
}

void Counter::displaydollars() { // makes private integer public
	cout << dollars;
}

void Counter::displaytendollars() { // makes private integer public
	cout << tendollars;
}

void Counter::reset() {
	cents = dimes = dollars = tendollars = 0;
	overflowFlag = false;
}

void Counter::display() {
	cout << tendollars << dollars
		<< dimes << cents;
}

bool Counter::overflow() {
	return overflowFlag;
}

Counter::Counter() :cents(0), dimes(0), dollars(0), tendollars(0), overflowFlag(false) {
}

void Counter::incr1() {  //increments the cent amount
	if (cents < 9)
		cents++;
	else {
		cents = 0;
		if (dimes < 9)
			dimes++;
		else {
			dimes = 0;
			if (dollars < 9)
				dollars++;
			else {
				dollars = 0;
				if (tendollars < 9)
					tendollars++;
				else
					overflowFlag = true;
			}
		}
	}
}

void Counter::incr10() {  //increments the ten cents amount
	if (dimes < 9)
		dimes++;
	else {
		dimes = 0;
		if (dollars < 9)
			dollars++;
		else {
			dollars = 0;
			if (tendollars < 9)
				tendollars++;
			else
				overflowFlag = true;
		}
	}
}

void Counter::incr100() {  //increments the dollar amount
	if (dollars < 9)
		dollars++;
	else {
		dollars = 0;
		if (tendollars < 9)
			tendollars++;
		else
			overflowFlag = true;
	}
}

void Counter::incr1000() {  //increments the ten dollar amount
	if (tendollars < 9)
		tendollars++;
	else {
		tendollars = 0;
		overflowFlag = true;
	}
}