Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am having a difficult time writing a C++ program. Here is my problem:
Use a single-subscripted array to solve the following problem. A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who gross $5000 in sales in a week receives $200 plus 9 percent of $5,000, or a total of $650. Write a program (using an array of counters)that determines how many of the salespeople earned salaries in each of the following ranges (assume that each salesperson's salary is truncated to an integer amount):
200-299
300-399
$400-499
500-599
600-699
700-799
800-899
900-999
1000 and overOk, the only instruction from my instructor is that the program should prompt the user for input.
I don't know how to even start this program.

same prob here !
Use a single-subscripted array to solve the following problem. A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 19 percent of their gross sales for that week. For example, a salesperson who grosses $5000 in sales in a week receives $200 plus 19 percent of $5000, or a total of $1150. Write a program, using an array of counters, that determines how many of the salespeople earned salaries in the following ranges (assume that each salesperson's salary is truncated to an integer amount):
First range : $200 - $299 Second range : $300 - $399
Third range : $400 - $499 Fourth range : $500 - $599
Fifth range : $600 - $699 Sixth range : $700 - $799
Seventh range : $800 - $899 Eighth range : $900 - $999
Ninth range : $1000 and overUse a sentinel-controlled loop to allow the user to enter any number of amounts of gross weekly sales to process. Use the value -1 as your sentinel value to stop entering gross sales amounts and display the final results.

#include <iostream>
using namespace std;
int main()
{const int rangeSize=9;
int saleAmt = 0;
int i, counter[rangeSize];
double total;
{
while ( saleAmt != -1 );
cout << "Enter Gross Weekly Sales, or -1 to end: " << endl;
cin >> saleAmt;
}
for(i=0;i<rangeSize;i++)
counter[i]=0;
for(i=0;i<rangeSize;i++)
{
total = saleAmt[i] * 0.19 + 200;
if ( total <1000 )
counter [int ( total / 100 ) - 2 ]++;
else
counter[8]++;
}int rangeMin, rangeMax;
for(i=0; i<8; ++i)
{
rangeMin=i*100+200;
rangeMax=rangeMin+99;
cout << " $ " << rangeMin << " - $ " << rangeMax
<< ": " << counter[i] << endl;
}
cout << "$1000 and over: " << + counter[8] <<
endl;return 0;
}is what i have so far... doesn't work.. im not sure if it's right... i missed a LOT of class and im not sure i understand arrays really. :(... my text is not clear at all

"system("format :");" i think this is too heavy-handed... at least this guy is honest (" don't know how to even start this program.")
here: http://www.computing.net/programming/wwwboard/forum/7407.html
wtk :)

ok lol. i have tried. my specific problem is that im not sure i understand arrays... i reckon i can post what i did first... which is a total and complete NON-ARRAY... although it seems to work fine.
#include <iostream>
using namespace std;int main()
{
const int arraySize = 9;
int saleAmt = 0;
int total = 0;
int n[ arraySize ] = {0};while ( saleAmt != -1 )
{
cout << "Enter Gross Weekly Sales, or -1 to end: " << endl;
cin >> saleAmt;
total = saleAmt * .19 + 200;
if (total > 199 && total < 300)
n[ 0 ]++;
if (total > 299 && total < 400)
n[ 1 ]++;
if (total > 399 && total < 500)
n[ 2 ]++;
if (total > 499 && total < 600)
n[ 3 ]++;
if (total > 599 && total < 700)
n[ 4 ]++;
if (total > 699 && total < 800)
n[ 5 ]++;
if (total > 799 && total < 900)
n[ 6 ]++;
if (total > 899 && total < 1000)
n[ 7 ]++;
if (total > 1000 )
n[ 8 ]++;
if (total < 200)
cout << "Results:" << endl;
else cout << "Weekly Salary is: " << total << endl;}
cout << n[ 0 ] << "people made $200 - $299 this week." << endl;
cout << n[ 1 ] << "people made $300 - $399 this week." << endl;
cout << n[ 2 ] << "people made $400 - $499 this week." << endl;
cout << n[ 3 ] << "people made $500 - $599 this week." << endl;
cout << n[ 4 ] << "people made $600 - $699 this week." << endl;
cout << n[ 5 ] << "people made $700 - $799 this week." << endl;
cout << n[ 6 ] << "people made $800 - $899 this week." << endl;
cout << n[ 7 ] << "people made $900 - $999 this week." << endl;
cout << n[ 8 ] << "people made $1000 or more this week." << endl;
return 0;
}u see what i did next..(posted previously) and as of today, i am rather stuck. i have tried, i will continue to try... i think i just need a nudge in the right direction.
yahoo messenger: kimmie_dawg (always on)
msn: k2theimmie@hotmail.com (rarely on.. but i can get on ! )

Okay...It's obvious kimmie has been trying this, although there's no evidence that Giacomo has. I like your approach of doing it a more familiar way kimmie, and working toward the goal. Anyhow, here are some tips:
You seem to understand arrays just fine. Your understanding deficiency is in loops. I'll make some comments:
{
while ( saleAmt != -1 );
cout << "Enter Gross Weekly Sales, or -1 to end: " << endl;
cin >> saleAmt;
}First and foremost, what are the brackets doing outside the loop?
while (expr)
{
dothis;
}Secondly, notice that your loop above correctly prompts the user for input until -1 is entered, and stores each value in the variable saleAmt. Unfortunately, you don't do anything with this variable, so it is simply overwritten each iteration, and no sales are recorded. You need to extend this while loop to cover both entering in and processing the data.
for(i=0;i<rangeSize;i++)
counter[i]=0;This loop is correct (although maybe unnecessary...I can't remember if C inititializes arrays). But it only needs to be done once...Put this badboy right after you declare the variables...Not in the while loop above.
for(i=0;i<rangeSize;i++)
{
total = saleAmt[i] * 0.19 + 200;if ( total <1000 )
counter [int ( total / 100 ) - 2 ]++;else
counter[8]++;
}Whoa! What is this? We better go line by line:
saleAmt[i] - saleAmt is a regular old int...not an array. I see what you're trying to do here, but it's wrong. The only array we need is the one that keeps track of the number of employees in each salary range. We deal with each employee separately, then throw them away after we're done. No need to keep them around. This does not need to be in any loop except the main while loop...We do this calculation once per employee.total = saleAmt*0.19 + 200;//this is correct
if ( total <1000 )
counter [int ( total / 100 ) - 2 ]++;else
counter[8]++;VERY clever. Nicely done. I assume the int casting truncates (or takes the floor of) the value and doesn't round. I think this is true, but can't remember.
for(i=0; i<8; ++i)
{
rangeMin=i*100+200;
rangeMax=rangeMin+99;
cout << " $ " << rangeMin << " - $ " << rangeMax
<< ": " << counter[i] << endl;
}
cout << "$1000 and over: " << + counter[8] <<
endl;Perfect. You were actually closer to a working solution than I originally thought.
So let's write the correct order in pseudocode:
declare variables
initialize counter array
while (input != -1)
{
get input
calculate sales total
increment proper counter
}
for every entry in counter
{
print out counter summary
}Good luck,
-SN

i am seriously wondering why i took c++ for fun... i wonder, where have i gone wrong? :( someone plz point me toward the light...
#include <iostream>
using namespace std;
int main()
{const int blah=9;
int saleAmt;
int i, counter[blah];
int total;
saleAmt = 0;
cout << "Enter Gross Weekly Sales, or -1 to end: " << endl;
cin >> saleAmt;
while ( saleAmt != -1 )
{
total = saleAmt * 0.19 + 200;
for( i = 0 ; i < blah ; i++ )
counter [i] = 0;
cout << "Weekly Salary with Commission is: $" << total << endl;
if ( total <1000 )
counter [int ( total / 100 ) - 2 ] ++ ;
else
counter[8]++;
}int rangeMin, rangeMax;
for(i=0; i<8; ++i)
{
rangeMin = i * 100 + 200 ;
rangeMax = rangeMin + 99 ;
cout << " $ " << rangeMin << " - $ " << rangeMax
<< ": " << counter[i] << endl;
}
cout << "$1000 and over: " << + counter[8] <<
endl;return 0;
}

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |