If necessary, create a new project named Advanceed28 Project and save it in the
ID: 3808543 • Letter: I
Question
If necessary, create a new project named Advanceed28 Project and save it in the Cpp8Chap11 folder. Also create a new source file named Advance28.ccp. The program should declare a 20-element, one dimensional int array named commision. Assign the following numbers to the array: 300, 500, 200, 150, 600, 750, 900, 150, 100, 200, 250, 650, 300, 750, 800, 350, 250, 150, 100, and 300. the program should prompt the user to enter a commission amount from 0 to 1000. It then should display the number of salespeople who earned that commission. Use a sentel value to end the program. Use the application to answer the following questions: a. How many salespeople earned a commission of 100? How many salepeople earned a commission of 300? How many salepeople earned a commission of 50? How many salespeople earned a commission of 900?
Explanation / Answer
Program:
#include <iostream>
using namespace std;
int main ()
{
// Declaration of the commission array
int commission[20] = {300, 500, 200, 150, 600, 750, 900, 150, 100, 200, 250, 650, 300, 750, 800, 350, 250, 150, 100, 300};
// Declaration of a number to take input for commission to be checked
int num=0;
// Infinite loop, using sentel value -1 to break out
while(1)
{
// Input for a value of commission to be checked
cout << "Enter a commission amount from 1 to 1000: ";
cin >> num;
// Breaking out when num is equal to -1, the sentel value
if(num==-1)
break;
// Count variable to keep track of the count of matching commissions
int count = 0;
// Loop to check this commission value
for(int i=0; i<20; i++)
{
if(commission[i]==num)
count++;
}
// Printing the Output on screen
cout << endl << "Number of people who earnt " << num << " as commission are: " << count << endl << endl;
}
}
OUTPUT:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.