Can anyone help me with this C++ assignment on looping? As the manager of Sunshi
ID: 3668237 • Letter: C
Question
Can anyone help me with this C++ assignment on looping?
As the manager of Sunshine Hot Tubs, you would like to create a report that tracks the sales of your employees. You currently have three sales people - Reid, Jarid, and Nicole. Write a program that prompts the user for a salesperson's initial ('R', 'J', or 'N') then allows the user to enter up to 4 sale amounts at a time for the salesperson. Calculate and display the salesperson's commission as 13% of the sales entered. Add the commission to a running total for that salesperson. The program should terminate when the user types a 'Z' A final report should display each salesperson's total commission earned along with their average sales. Save the file as HotTub .cpp Additional information: Your program should efficiently implement all 3 of the looping constructs. Implement shortcut operators where appropriate. Your program should handle invalid entries for the salesperson's initials. Once a valid salesperson's initial has been entered, the program should continue prompting the user for a valid number of sales - (no negative values or values exceeding the limit of 4 sales entries per salesperson at a time). Output should be labeled, aligned, and formatted to 2 decimal places. break; statements may only be implemented in switch statements; not in if or looping statements, Make sure you are using the correct data types and descriptive variable names. Add a comment to the top of your program that includes your name, the program name, and a description of the program code. Include comments throughout your program. Test your calculations!Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
double reid = 0, jarid = 0, nicole = 0;
cout << fixed << setprecision(2);
while(true){
string employee;
int numOfSales;
do{
cout << "Enter the salesperson's initial: ";
cin >> employee;
if(employee.compare("R") != 0 && employee.compare("N") != 0 && employee.compare("J") && 0 || employee.compare("Z") && 0) cout <<" Correct initials are 'J', 'N', 'R', 'Z' only ";
}while(employee.compare("R") != 0 && employee.compare("N") != 0 && employee.compare("J") != 0 && employee.compare("Z") != 0);
if(employee.compare("Z") == 0) break;
do{
cout << "Enter the number of sales: ";
cin >> numOfSales;
if(numOfSales < 0 || numOfSales > 4) cout << "number of sales should be between 1 and 4, inclusive ";
}while(numOfSales < 0 || numOfSales > 4);
cout << "Enter " << numOfSales << " sale amounts: ";
double saleAmount = 0, temp;
for(int i = 0; i < numOfSales; i++){
cin >> temp;
saleAmount += temp;
}
cout << "Total sale amount: " << saleAmount << " ";
cout << "Salesman's commission: " << 0.13 * saleAmount << " ";
if(employee.compare("R") == 0){
reid += saleAmount;
}
else if(employee.compare("J") == 0){
jarid += saleAmount;
}
else if(employee.compare("N") == 0){
nicole += saleAmount;
}
}
cout << "Ried's sale amount: " << reid << " ";
cout << "Ried's commission: " << reid * 0.13 << " ";
cout << "Jarid's sale amount: " << jarid << " ";
cout << "Jarid's commission: " << jarid * 0.13 << " ";
cout << "Nicole's sale amount: " << nicole << " ";
cout << "Nicole's commission: " << nicole * 0.13 << " ";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.