Kay , i am remaking ALL excersices of my c++ book. ( c++ How to program, fifth edition)
and i just entered the stage about arrays and vectors.... , this is my assignment:
Code:
Use a one-dimensional array to solve the following problem:
A company pays its salespeople on a commission basis.
The salespeople each receive $200 per week plus 9 percent
of their gross sales for that week. For example,
a salesperson who grosses $5000 in sales in a week receives $200 plus 9 percent
of $5000, 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 over
this is what i made :
CLASS HEADER
Code:
#ifndef classB_0 header.h
#define classB_0 header.h
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
using std::getline;
class earningslog
{
public:
static const int employees = 20; // 20 employee's
earningslog (float []);
void Setearnings (float []);
void outputbar (int []);
private:
int totalearnings[employees];
};
#endif
CLASS IMPLEMENTATION
Code:
#include "ClassB_0 header.h"
// 20 employee's
earningslog::earningslog (float procentless[])
{
Setearnings (procentless);
}
void earningslog::Setearnings (float procentless[])
{
const int frequencysize = 9;
int frequency[frequencysize] = {0};
for (int x = 0; x < employees ; x++)
{
totalearnings[x] = ( (procentless[x]*0.09) + 200 );
if ( (totalearnings[x] ) > 1000)
{
frequency[8]++;
}
else
{
frequency[ (totalearnings[x] / 100 ) ]++; // problem: cast to int makes some
// values turn to 0
}
cout << endl;
}
outputbar (frequency);
}
void earningslog::outputbar (int frequency [])
{
int l = 0;
for (int x = 200; x < 1000; x+=100 ,l++)
{
cout <<x<<"-"<<x+99<<": ";
cout << frequency[l] << endl;
}
cout <<"1000 and over:"<< frequency[8] << endl;
}
DRIVER PROGRAM (main)
Code:
#include "ClassB_0 header.h"
int main ()
{
float lol[earningslog::employees] =
{
1000,1500,2000,2500,3000,3500,4000,4000,5000,5500,
7000,8000,3000,6000,9999,8888,7777,6666,5555,4444
};
earningslog zor (lol);
}
output:
Code:
200-299: 0
300-399: 0
400-499: 1
500-599: 2
600-699: 2
700-799: 4
800-899: 3
900-999: 2
1000 and over:2
=> problem is that there are 20 employees and , and when i count my output it is only 16
i already know where the problem might be , and i marked that section bold, i just dont know how to solve the problem.