The problem with this code is that every time I loop, it back to start the rate increases and don't stay at a fix value of 0.10. like I finish my first run, the second time I repeat the code, the rate went from 25% as the last commission rate to 30%, the starting commission rate, to the new loop even.
My desire output only is:
Enter the sales: 2500
10% commission : Php 2500.00
15% commission : Php 3750.00
20% commission : Php 5000.00
25% commission : Php 6250.00
any fix for this?
#include<iostream>
using namespace std;
class Gas_commission{
private:
float res_coms = 0, val_sales = 0, val_rate = 0.10;
public:
void get_info(){
//input
cout << "-------------------------------------" << endl;
cout << "Enter the following to find the commission: " << endl;
cout << "-------------------------------------" << endl;
cout << "Enter Sales: ";
cin >> val_sales;
cout << "\n";
}
void get_res(){
//output
cout << "-------------------------------------" << endl;
for (int i = 1; i <= 4; i++){
res_coms = val_sales * val_rate;
cout << val_rate * 100 << "% " << "commission: Php " << res_coms << endl;
val_rate += 0.05; //the rate here keep increasing every time I loop the code
}
}
};
int main()
{
Gas_commission SALE;
char input;
do{
SALE.get_info();
SALE.get_res();
cout << "-------------------------------------" << endl;
cout << "\nDo you want to retry again (Y/N)? ";
cin >> input;
} while (input == 'Y' || input == 'y');
}