I've just learned about classes and objects and I'm having trouble trying to calculate an order for a price of cookies, which is the goal of the program.

The program is supposed to calculate the price of an order of cookies offering the best deal possible.

The program starts off with the user entering the price of cookies for the day.

The price is entered for: single cookie, half-dozen cookies and a dozen. After prices are entered the program for an order which it takes as input from the customer. After taking the order its supposed to calculate the price of the order and offer the best deal. This is where my problem is because there are constraints for the prices and what can be accepted as order inputs. Constraints are listed below:

1. All prices have to be greater than 0, (I'm ok with this)

2.The price of a half-dozen, must be less than the price of six individual cookies.

3. The price of a dozen must be less than the price of two half-dozen.

This sets up the possibility that the price of 5 or fewer could be greater than the price of a half-dozen, and price of 11 or fewer could be greater than price of a dozen. If this price situation does happen program is supposed to advise the customer of the better deal.

4. So the program can't accept the price of a halfdozen thats more than price of a dozen, or price of 6 single cookies thats more than a half dozen.

I'm not sure if I need more set or get methods or if its just my calculations.

I keep getting 0 for my totalPrice each run. I'm looking to understand how and what I've done wrong, so I can learn from this. Thank you all for you help.

Code:#include <iostream> #include <iomanip> #include <cstring> using namespace std; class CookieStore{ public: void setPrice(double, double, double); double calcPrice(int); void displayPrice(); private: double price1; double price6; double price12; double totalPrice; int amount; }; void CookieStore::setPrice(double a, double b, double c) { price1 = a; price6 = b; price12 = c; } double CookieStore::calcPrice(int amount) { double calcPrice1, calcPrice6, calcPrice12 = 0; calcPrice12 = (amount/12) * price12; calcPrice6 = (amount/6) * price6; calcPrice1 = amount * price1; totalPrice = calcPrice1; if((price1* 6) > calcPrice6) totalPrice = calcPrice6; else if((price6 * 2) > calcPrice12) return totalPrice; } void CookieStore::displayPrice() { cout << "Amount due is: " << totalPrice; } int main(){ CookieStore myCookieStore; double single, half, dozen; int order; cout << " Enter the price of a single cookie, half-dozen, and dozen" << endl; cin >> single >> half >> dozen; if(!cin.eof() && cin.good() && order > 0){ myCookieStore.setPrice(single,half,dozen); } else{ cout << "Invalid Prices entered" << endl; } cout << "How many cookies does the customer want to order?" << endl; cin >> order; while(!cin.eof() && cin.good() && order > 0){ myCookieStore.calcPrice(order); myCookieStore.displayPrice(); order = 0; } return EXIT_SUCCESS; }