this program is supposed to take in sales figures in dollars, convert them into a salary for the salesmen, and then display the number of salaries that fall within certain ranges (200-299 ect.)
However i keep getting incorrect results
no matter what i enter i keep getting 11 for the range 200-299 and 40 for the range over 1000
i would appreciate help finding the problem
here is the code for the 3 files
sales.h
/ Class automatically generated by Dev-C++ New Class wizard
#ifndef SALESREPORT_H
#define SALESREPORT_H
// No description
class SalesReport
{
public:
// class constructor
SalesReport( int [] );
int Salary( int );
void DisplaySalary();
private:
int sales[50]; // sales
};
#endif // SALESREPORT_H
sales.cpp
// Class automatically generated by Dev-C++ New Class wizard
#include <cstdlib>
#include "salesreport.h" // class's header file
#include <iostream>
#include <iomanip>
using namespace std;
SalesReport::SalesReport(int sArray[])
{
DisplaySalary();
}
int SalesReport::Salary( int oneSales )
{
return static_cast<int> ((oneSales* .09) + 200);
//return sales;
}
// End Salary
void SalesReport::DisplaySalary()
{
int arraysize = sizeof(sales)/sizeof(int);
int rangeA=0, rangeB=0 , rangeC=0, rangeD=0, rangeE=0, rangeF=0, rangeG=0, rangeH=0, rangeI=0;
for (int i =0; i <= arraysize; i++)
{
int salary = Salary( sales[i] );
if (200 <= salary && salary <= 299)
rangeA += 1;
else if (300 <= salary && salary <= 399)
rangeB += 1;
else if (400 <= salary && salary <= 499)
rangeC += 1;
else if (500 <= salary && salary <= 599)
rangeD += 1;
else if (600 <= salary && salary <= 699)
rangeE += 1;
else if (700 <= salary && salary <= 799)
rangeF += 1;
else if (800 <= salary && salary <= 899)
rangeG += 1;
else if (900 <= salary && salary <= 999)
rangeH += 1;
else
rangeI += 1;
}
// End while statement
cout << " Range Number" << endl;
cout << " $200-299 " << rangeA << endl;
cout << " $300-399 " << rangeB << endl;
cout << " $400-499 " << rangeC << endl;
cout << " $500-599 " << rangeD << endl;
cout << " $600-699 " << rangeE << endl;
cout << " $700-799 " << rangeF << endl;
cout << " $800-899 " << rangeG << endl;
cout << " $900-999 " << rangeH << endl;
cout << " $1000 and over " << rangeI << endl;
}
// End Display Salary
main.cpp
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include "salesreport.h"
using namespace std;
int main()
{
int i = 0;
int sales[i];
cout << "Enter a sales amount (negative to end): ";
cin >> sales[i];
while( sales[i] >= 0 )
{
cout << endl;
i++;
cout << "Enter a sales amount (negative to end): ";
cin >> sales[i];
}
SalesReport mySalesReport( sales );
system("PAUSE");
return(0);
}