Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

shirshah sahel
shirshah sahel
10,035 Points

Need some help with this C++ project?

if/else if

Description

Write a program that calculates a sales person’s monthly commission. The program asks the user to input the total sales amount for the month. It calculates the commission and displays a report including the sales amount and the commission earned. The commission is computed using the following:

15% commission for the first $2,000.00 sales 20% commission for the next $1,000.00 sales 25% commission for the next $500.00 sales 30% commission for the next $500.00 sales 35% commission for the remaining sales

#include <iostream>

using namespace std;

int main()
{

double sales;
double commission;

    cout << " Enter Sales Amount:" << endl;
    cin>> sales;

    if ( sales <= 2000.00)
{
            commission = .15 * sales;
}
else if (sales <= 3000.00)
{
            commission = (.15 * 2000.00) + ( (sales  2000.00) * .20 );
}
else if (sales <= 3500.00)
{
          commission = (.15 * 2000.00) + ( .20 * 1000.00) + ( (sales  3000.00) * .25 ) ;
}

    return 0;
}

Moderator edited: Markdown corrected so that code renders properly in the forums.

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! When I copy/paste your code into my IDE, it's not recognizing the characters you are using for the "minus" sign. But when I replace them with the character I generally use for a minus sign, it sees it fine. Check that you're using the correct character for the "minus".

Here are some other things to consider: you are trying to use the variable commission without initializing it. Also, you have no code that indicates what should happen if the sales is over 3500. According to your code, any salesperson who sells too much gets no commission at all. That seems hardly fair!

Finally, the requirements of your project require that you display the commision, but you aren't displaying them anywhere as of right now.

Hope this helps! :sparkles:

shirshah sahel
shirshah sahel
10,035 Points

Thank you Jennifer I was able to find out the solution. I was stuck on how to write the code for 3500 0r more.