Logic/math error?

Hello, I recently started an intro. to C++ class and am having some issues with a few of the online assignments. My code compiles but is not returning the expected output. I feel like it's an issue with my math but I'm stuck. Can anyone spot what I am doing wrong?

Thanks in advance!

-----------------------------------------------------------

Linda is starting a new cosmetic and clothing business and would like to make a net profit of approximately 10% after paying all the expenses, which include merchandise cost, store rent, employees’ salary, and electricity cost for the store.

She would like to know how much the merchandise should be marked up so that after paying all the expenses at the end of the year she gets approximately 10% net profit on the merchandise cost.

Note that after marking up the price of an item she would like to put the item on 15% sale.

Instructions
Write a program that prompts Linda to enter:

The total cost of the merchandise
The salary of the employees (including her own salary)
The yearly rent
The estimated electricity cost.
The program then outputs how much the merchandise should be marked up (as a percentage) so that Linda gets the desired profit.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  #include <iostream>
#include <iomanip>

using namespace std;

int main() {
    
    double merchCost;
    double salary;
    double rent;
    double electricity;
    double expenses;
    double markupPrice;
    double saleMarkupPrice;
    int markupPercent;
        
    cout << "Enter the total cost of the merchandise:" << endl;
    cin >> merchCost;
    
    cout << "Enter the salary of the employees (including your own):" << endl;
    cin >> salary;
        
    cout << "Enter the yearly rent:" << endl;
    cin >> rent;
        
    cout << "Enter the estimated electricity cost:" << endl;
    cin >> electricity;
    
    expenses = merchCost + salary + rent + electricity;
    
    markupPrice = (expenses * 0.10);
    
    saleMarkupPrice = (expenses + markupPrice) * 0.15;
        
    markupPercent = (markupPrice + saleMarkupPrice) / ((expenses + markupPrice + saleMarkupPrice) * 100);
    
    cout << "Your merchandise should be marked up " << markupPercent << "%" << endl;
   
    return 0;
}
You should always show exactly what you expect and exactly what it is actually doing, not just "it's not doing what I expect".

However, it looks like you may not be multiplying by 100 correctly for the percentage at the end. Try removing the close paren after the 100, and it's partner earlier in the expression.
Last edited on
Basic 101 debug lesson.
1
2
3
4
5
6
7
8
    expenses = merchCost + salary + rent + electricity;
    cout << "Debug: expenses=" << expenses << endl;

    markupPrice = (expenses * 0.10);
    cout << "Debug: markupPrice=" << markupPrice << endl;
    
    saleMarkupPrice = (expenses + markupPrice) * 0.15;
    cout << "Debug: saleMarkupPrice=" << saleMarkupPrice << endl;

It's software, so you can make it do whatever YOU want, even if it's not what someone else wants (like your assignment setter).
Anything which might make your life easier in understanding what's going on is fair game.

The point being to isolate the point in the code where everything makes sense suddenly stops making sense.


Sure, when you're happy, you take them all out again (or just make them comments).
1
2
3
4
5
6
7
8
    expenses = merchCost + salary + rent + electricity;
    //cout << "Debug: expenses=" << expenses << endl;

    markupPrice = (expenses * 0.10);
    //cout << "Debug: markupPrice=" << markupPrice << endl;
    
    saleMarkupPrice = (expenses + markupPrice) * 0.15;
    //cout << "Debug: saleMarkupPrice=" << saleMarkupPrice << endl; 


Last edited on
salem c + 1
Note that in this case statements 2 and 3 do not change the 'expenses'
and statement 3 does not change the 'markupPrice'.
Therefore, we can change order of statements without changing the output:
1
2
3
4
5
6
7
    expenses = merchCost + salary + rent + electricity;
    markupPrice = (expenses * 0.10);
    saleMarkupPrice = (expenses + markupPrice) * 0.15;

    cout << "Debug: expenses=" << expenses << endl;
    cout << "Debug: markupPrice=" << markupPrice << endl;
    cout << "Debug: saleMarkupPrice=" << saleMarkupPrice << endl;

That makes comment/uncomment easier. Alas, this is not always possible.

Let:
1
2
3
E = expenses
M = markupPrice
S = saleMarkupPrice

You wrote:
1
2
3
4
5
6
7
8
9
10
11
12
13
P = (M + S) / ((E + M + S) * 100);
// substitute S = (E + M) * 0.15
P = (M + (E + M) * 0.15) / ((E + M + (E + M) * 0.15) * 100);
// substitute M = E * 0.10
P = (E * 0.10 + (E + E * 0.10) * 0.15) / ((E + E * 0.10 + (E + E * 0.10) * 0.15) * 100);
// rearrange (E * 0.10 + (E + E * 0.10) * 0.15)
P = E*(0.10 + 0.15 + 0.015) / ((E + E * 0.10 + (E + E * 0.10) * 0.15) * 100);
// rearrange (E + E * 0.10 + (E + E * 0.10) * 0.15)
P = E*(0.10 + 0.15 + 0.015) / (E*(1 + 0.10 + 0.15 + 0.015) * 100);
// addition
P = (E * 0.265) / (E * 1.265 * 100);
// simplify
P = (0.265 / 1.265) / 100 = 0.209 / 100 = 0.00209

Somehow I have a feeling that 0.002 is not the answer you are looking for.

Note also that the result of the equation does not depend on expenses. It is all about the 10% and the 15%.
The problem is in your math.

First:
after marking up the price of an item she would like to put the item on 15% sale.
saleMarkupPrice = (expenses + markupPrice) * 0.15;
That code is incorrect. Consider this:
If something costs $100 and I mark it up 10%, the price is $110.
If I take that $110 item and mark it down 10%, the new price is $99, not $100.

Mathmatically, you want the discounted saleMarkupPrice to be expenses + markupPrice:
saleMarkupPrice - 0.15*saleMarkupPrice = expenses + markupPrice.
Solve for saleMarkupPrice.

Second:
The program then outputs how much the merchandise should be marked up (as a percentage)
1
2
3
    markupPrice = (expenses * 0.10);
    saleMarkupPrice = (expenses + markupPrice) * 0.15;
    markupPercent = (markupPrice + saleMarkupPrice) ...

You have added expenses twice.

You might find this easier if you use more descriptive variable names:
1
2
3
4
5
6
7
8
9
    double merchCost;           // const of merchandise
    double salaryCost;          // cost of salaries
    double rentCost;            // cost of rent
    double electricityCost;     // cost of electricity
    double expenses;            // total expenses

    double netIncome;           // money you need to bring in
    double totalListPrice;      // list price of all merchandise
    int markupPercent;          // percent the merh must be marked up 


Here's a sample run of my version (with debugging output):
Enter the total cost of the merchandise:
100000
Enter the salary of the employees (including your own):
60000
Enter the yearly rent:
60000
Enter the estimated electricity cost:
12000
total expenses: 232000
net Income required: 255200
Total list price needed to generate net income: 300235
Merchandise Markup: 200%
Your merchandise should be marked up 200%


Topic archived. No new replies allowed.