# Thread: Price Calculation Problem using Class

1. ## Price Calculation Problem using Class

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;

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 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)

}

{
cout << "Amount due is: " << totalPrice;

}

int main(){
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){
}
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){
order = 0;
}

return EXIT_SUCCESS;
}```

2. You have an else if at the end of calcprice that doesn't seem to have anything to do.

3. ## Addition to the end of else if

Sorry,

I meant to have after the else if;

totalPrice = calcPrice12;

Not sure if that even makes a difference, but thats what I meant to have, thanks

4. Okay. That should be setting things, but probably not the way you want. Ask yourself this: if the user asks for seven cookies, what price is (s)he going to be charged?

5. Ok, thanks I see what you saying now. So...if the user asks for seven cookies they would be charged for the price of a dozen plus the price of one single. I think what I need to do then in my calcPrice method is set up a series of if statements to determine this? I will rework that and see if it works and re-post. Thank You