related on the first question...which is getting the commission,,,
let me correct it..if you run this code the sample output will be like below;
the problem is I dont know which one will be first to make a code.

the output will be like this;
sample output
monthly sale=15250
commission=610

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

last output;
monthly sale=45280
commision=170

Dani AI

Generated

The three results shown by (a normal sale, a negative sale that should be rejected, and a large sale) point to two important rules for an if/else commission routine: validate input first, and make the range checks non-overlapping so only one branch can match. As noted, wrap the logic in a loop if the same calculation must run repeatedly. As requested, posting the current code and the exact unexpected output will let helpers point to the precise bug.

A compact pattern in C++ is to put the invalid check first, then an ordered chain of tests (either descending or ascending) that return the appropriate rate. Example (replace thresholds and rates with the real rules):

#include <iostream>
#include <cmath>

double computeCommission(double sale) {
    if (sale < 0.0) return NAN;            // invalid
    if (sale > 50000.0) return sale * 0.04;
    if (sale > 20000.0) return sale * 0.03;
    if (sale > 10000.0) return sale * 0.02;
    return sale * 0.01;
}

Testing tips: check boundary values (exactly 0, exactly each threshold), test negative input, and test very large values. Use double for calculation and round or format when printing if an integer is required. Avoid overlapping conditions (for example, use > consistently when scanning from high to low, or use <= when scanning low to high). If the program should repeat for a fixed number of runs, a for loop is simplest; for interactive input, read until EOF or a sentinel.

If further debugging is needed, include the minimal reproducible code, the compiler and platform, the inputs used, and the actual vs expected output — that makes targeted fixes much quicker.

Recommended Answers

All 3 Replies

the problem is I dont know which one will be first to make a code.

i don't understand what you want to say

the output will be like this;
sample output
monthly sale=15250
commission=610

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

last output;
monthly sale=45280
commision=170

where is the code you've written to produce such output ?
But as a hint , i can recommend you to use of loop.

loop will help to produce the result more times(Looping allows to repeat statements).you need not write the code for 3 times , just put it inside loop body and put such condition which ensures that loop will run 3 times(i mean that condition must be true till 3 iteration).

for more information on loop , see my tutorial on loop , here

If you want us to helpful, please post your code.

Closed. Continued here

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.