Here is my prompt: 1. Write a program that incorporates function modules 2. Use
ID: 3627046 • Letter: H
Question
Here is my prompt:1. Write a program that incorporates function modules
2. Use appropriate function declarations
3. Use function headers and write function procedure
4. Use function Calls appropriately
Problem statement:
Write a program that displays the commission of a salesman using a function.
Define a function called CalcCommision.Your program should prompt the user to enter the sales amount in the. Then the function Main module CalcCommision is called by passing the sales to calculate the commission and return the value to the main module. The Main Module will display the sales and the commission.
Your program will continue asking for the sales until the user types a negative number for sales, then the program should ask the user, if he/she wants to terminate the program. The program terminates if the user answers yes or y.
Procedure or Details:
The following table is used to calculate the commission:
Sale Amount Commission
---------------- ---------------------------
0 – 999 3.5%
1000 – 1999 4.0%
2000 – 2999 4.5%
3000 or above 5.0%
Here is my program thus far:
#include <iostream>
#include <iomanip>
using namespace std;
double CalcCommision (double &sale)
{
double commission;
if(sale <=999)
commission= sale * .035; //This equation calculate commission that is 3.5% of sales between $0 and $999
else if(sale >= 1000 <=1999)
commission= sale * .040; //This equation calculates commission that is 4% of sales between $1000 and $1999
else if(sale >= 2000 <=2999)
commission= sale * .045; //This equation calculates commission that is 4.5% of sales between $2000 and $2999
else if (sale <=3000)
commission= sale * .050; //This equation calculates commission that is 5% of sales $3000 or greater
return commission;
}
int main()
{
double sale;
sale = 0; // initialize sale
cout << "In order to calculate the commision of a sales, you must enter the sales amount." <<endl
<< "Once the sales amount is entered, the commission will be displayed." <<endl
<< endl
<< "In order to exit the program, you must enter a negative number." << endl;
while (sale >= 0) //the while statement starts loop, while statement is being utilized if a positive number is entered
//once an ammount is entered, the commission value returned to main module is displayed with CalcCommission
{
cout << endl;
cout << endl;
cout << endl;
cout << "Please enter the sales amount: $ ";
cin >> sale;
cout << endl;
cout << "Sales: $" << sale << "Commission Earned: $" << CalcCommision (sale) << endl;
}
// if a negative number is entered, program jumps here to ask user if they would like to terminate the program
cout << endl;
cout << endl;
cout<< endl;
cout << "Please type 'yes' or 'y' if you wish to terminate the program.";
return 0;
}
QUESTIONS:
How do I make this program end when I enter yes or y?
I'm not sure if I should have used the while command.
Should I have used something else?
When I run the program, and enter a negative number, it still does the calculations. I don't want it to do that!
I need it to loop until I enter a negative number, and when I enter a negative number, I want to ask if I want to terminate (not do the calculations). If I don't type yes or y, I want it to run the loop again!! AHHHH!!! Someone please help!!
Explanation / Answer
try this
and please rate -thanks
#include <iostream>
#include <iomanip>
using namespace std;
double CalcCommision (double &sale)
{
double commission;
if(sale <=999)
commission= sale * .035; //This equation calculate commission that is 3.5% of sales between $0 and $999
else if(sale >= 1000 <=1999)
commission= sale * .040; //This equation calculates commission that is 4% of sales between $1000 and $1999
else if(sale >= 2000 <=2999)
commission= sale * .045; //This equation calculates commission that is 4.5% of sales between $2000 and $2999
else if (sale <=3000)
commission= sale * .050; //This equation calculates commission that is 5% of sales $3000 or greater
return commission;
}
int main()
{
string yes;
double sale;
sale = 0; // initialize sale
cout << "In order to calculate the commision of a sales, you must enter the sales amount." <<endl
<< "Once the sales amount is entered, the commission will be displayed." <<endl
<< endl
<< "In order to exit the program, you must enter a negative number." << endl;
cout << "Please enter the sales amount: $ ";
cin >> sale;
while (true) //the while statement starts loop, while statement is being utilized if a positive number is entered
//once an ammount is entered, the commission value returned to main module is displayed with CalcCommission
{if(sale>=0)
{cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << "Sales: $" << sale << "Commission Earned: $" << CalcCommision (sale) << endl;
}
else
// if a negative number is entered, program jumps here to ask user if they would like to terminate the program
{
cout << endl;
cout << endl;
cout<< endl;
cout << "Please type 'yes' or 'y' if you wish to terminate the program.";
cin>>yes;
if(yes.compare("yes")==0||yes.compare("y")==0)
return 0;
}
cout << "Please enter the sales amount: $ ";
cin >> sale;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.