• my assignment is to find the commission of each monthly sales,how can i get the right answer?
monthly sales is 0-19,999(4%)/ 20,000-29,999(5%) /30,000-39,999(6%) / 40,000-49,999(7%)
50,000-above(9%)
using if/else statement

then,,how can I make a flow chart related on this problem.?

can you plese lead me to the right answer?

Dani AI

Generated

A clear, maintainable approach is: validate the input first (reject negative sales), then test the commission bands with an else-if ladder from highest to lowest. This keeps each decision simple and avoids overlapping ranges. As suggested, an if...else-if structure is the right pattern, and 's reminder about having an int main() is important for a complete C++ program.

Flowchart (simple, top-to-bottom): Start → Input monthly_sales → Decision: monthly_sales < 0 ? → Invalid / End. Otherwise: Decision: monthly_sales >= 50000 ? → 9% → Output → End; else >= 40000 ? → 7% → ... then >= 30000 ? → 6%; >= 20000 ? → 5%; else 4% → Output → End. Placing validation first answers the "which one comes first" question: the validation decision is first, then the highest-threshold check.

Example C++ implementation (keeps logic separate, shows rounding to cents):

#include <iostream>
#include <iomanip>
#include <cmath>

double commissionRate(double sales) {
    if (sales >= 50000.0) return 0.09;
    else if (sales >= 40000.0) return 0.07;
    else if (sales >= 30000.0) return 0.06;
    else if (sales >= 20000.0) return 0.05;
    else if (sales >= 0.0)     return 0.04;
    return -1.0; // invalid marker
}

int main() {
    double sales;
    std::cout << "Enter monthly sales: ";
    if (!(std::cin >> sales)) return 0;
    double rate = commissionRate(sales);
    if (rate < 0) {
        std::cout << "Invalid sales amount\n";
    } else {
        double commission = std::round(sales * rate * 100.0) / 100.0;
        std::cout << std::fixed << std::setprecision(2)
                  << "Commission = " << commission << '\n';
    }
    return 0;
}

Notes and troubleshooting: use double for money calculations or track cents as integers if exactness is critical; test boundary values (0, 19999.99, 20000, 29999.99, 50000) to confirm the correct bracket is chosen. Also note an error in 's sample: a sale of 45,280 at 7% yields 3,169.60, not 170.

Recommended Answers

All 9 Replies

Try stating it in words:

if sales are less than 20000, commission is 4%

otherwise, if sales are less than 40000, commission is 6%

otherwise, if sales are less than 50000, commission is 7%

otherwise, commission is 9%

With this, you can create a flowchart with 3 decision shapes.

Remember, when you have range problems like this, as long as you use if...else if structure, you don't have to test for low to high values for each range, just whichever limit you're looking at for each new block.

but i still confused in deciding which one will be the first chart?

Jain, we don't do your homework for you. Please make an attempt to solve the problem, and then post your code here. Then we can help you. Your post is not clear to us - or me at least.

for us to help you we need to see some code to know where you are going

if you going to run the code you have typing,this is the output you will be seen..
..
sample output
monthly sale=15250
commission=610

next output ;
monthly sale=-5
commission=invalid output

last output;
monthly sale=45280
commision=170

the code is example like this..
#include (iostream)
using namespace std;

int sale;
double commission;
int result;

cout<<"enter monthly sales"<<endl;
cin>>monthly sales;

then...<.help me!!!>`

jaina and i..is the same person

what do you mean of 5 post within 5 days?
i need to post 5 problem related to my topic...??

i dont understand what are the 15 reputation points in order to unlock the full website? what does it mean...who can tell me,,please!

Where is your 'int main()' function ?

Every C or C++ program needs one.

#include <iostream> // use <  > brackets

using namespace std;

int main()
{
    // your code goes here ...

    double monthly_sales, commission;

    bool more = true;
    do // main loop where you input & output ... 
    {

        cout << "Enter monthly sales: " << flush;
        cin >> monthly_sales;
        while( cin.get() != '\n' ); // eat '\n' etc.

        // your code goes here to calculate and
        // output results ...

        cout << "More (y/n) ? " << flush;
        int reply = cin.get();
        if( reply != '\n' ) while( cin.get() != '\n' ) ; // flush cin stream ...
        more = (reply != 'n' && reply != 'N' ); // defaults to yes (more) ...

    }
    while( more );

    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.