#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# help with array and counting/counters

Member Posts: 7
Can someone please show me what i am doing wrong with my code? I have the salary calculation part but now i have to count the amount of salaries in the range.

[code]
#include

using std::cout;
using std::cin;
using std::endl;

#include

int main()
{

int array[ 9 ] = { 0 };
double sales, //sales amount input by user
commission = .09, //9 percent commission
pay = 200.00; //dollar amt paid to employee

cout << "Enter sales in dollars, -1 to end: "; //prompt for input
cin >> sales; // reads the sales dollars entered

while ( sales != -1 ) { //sentinel value

sales = sales * commission + pay; //pay calculation

cout << "Pay is: " << sales <<endl; //gives the employees pay total

if sales >= 200 AND sales <= 399 Then
array(0) = array(0) + 1
else if sales >= 400 AND sales <= 599 Then
array(1) = array(1) + 1
else if sales >= 600 AND sales <= 799 Then
array(2) = array(2) + 1
else if sales >= 800 AND sales <= 999 Then
array(3) = array(3) + 1
else if sales >= 1000 Then
array(4) = array(4) + 1

}

cout << "Employees in the range:";

for ( int i = 1; i < 10; ++i )

cout << "
\$" << i << "00-\$" << i << "99 : " ;

cout << "
Over \$1000: " << sales << endl;

return 0;

}

[/code]

• Member Posts: 32
: Can someone please show me what i am doing wrong with my code? I have the salary calculation part but now i have to count the amount of salaries in the range.
:
: [code]
: #include
:
: using std::cout;
: using std::cin;
: using std::endl;
:
: #include
:
: int main()
: {
:
:
:
: int array[ 9 ] = { 0 };
: double sales, //sales amount input by user
: commission = .09, //9 percent commission
: pay = 200.00; //dollar amt paid to employee
:
:
:
:
: cout << "Enter sales in dollars, -1 to end: "; //prompt for input
: cin >> sales; // reads the sales dollars entered
:
:
: while ( sales != -1 ) { //sentinel value
:
:
: sales = sales * commission + pay; //pay calculation
:
:
: cout << "Pay is: " << sales <<endl; //gives the employees pay total
:
:
:
: if sales >= 200 AND sales <= 399 Then
: array(0) = array(0) + 1
: else if sales >= 400 AND sales <= 599 Then
: array(1) = array(1) + 1
: else if sales >= 600 AND sales <= 799 Then
: array(2) = array(2) + 1
: else if sales >= 800 AND sales <= 999 Then
: array(3) = array(3) + 1
: else if sales >= 1000 Then
: array(4) = array(4) + 1
:
:
: }
:
:
: cout << "Employees in the range:";
:
: for ( int i = 1; i < 10; ++i )
:
:
:
: cout << "
\$" << i << "00-\$" << i << "99 : " ;
:
: cout << "
Over \$1000: " << sales << endl;
:
:
:
:
:
:
:
: return 0;
:
:
: }
:
:
:
:
: [/code]
:
:
:
:

#include <iostream>
#include

using std::cout;
using std::cin;
using std::endl;

int main()
{
int array[ 9 ] = 0;
double sales; //sales amount input by user -- ; instead of ,
commission = .09; //9 percent commission -- the same mistake
pay = 200.00; //dollar amt paid to employee

cout << "Enter sales in dollars, -1 to end: "; //prompt for input
cin >> sales; // reads the sales dollars entered
while ( sales != -1 ) { //sentinel value
sales = sales * commission + pay; //pay calculation
cout << "Pay is: " << sales <<endl; //gives the employees pay total
// the line below was not C++ syntax
if ((sales >= 200) && (sales <= 399)) {
array(0)++; // your syntax is ok, but this is C++ shortcut
}
/* ... and so on ... take care of braces though here you can w/o them, but a very bad habit
else if sales >= 400 AND sales <= 599 Then
array(1) = array(1) + 1
else if sales >= 600 AND sales <= 799 Then
array(2) = array(2) + 1
else if sales >= 800 AND sales <= 999 Then
array(3) = array(3) + 1
else if sales >= 1000 Then
array(4) = array(4) + 1
*/
} // end if
// then after primary read before the loop, you should ask for a new input at the end of the loop
} // end while

cout << "Employees in the range:";
for ( int i = 1; i < 10; ++i ) { // use braces, they're good
// not sure what you want to do here? to print out the contents of the array?
cout << "
\$" << i << "00-\$" << i << "99 : " ;
cout << "
Over \$1000: " << sales << endl;
} // end for

return 0;
} // end main

hope it helps!
fule730

• Member Posts: 701 ✭✭✭
: Can someone please show me what i am doing wrong with my code? I have the salary calculation part but now i have to count the amount of salaries in the range.

[blue]I didn't really look over the sales equation, but this *may* be what you're after. You don't really need an in between range case since the else paths will be followed. C/C++ array indexing uses [], 'AND' is &&, and THEN isn't required after if.

Note: some things were changed for personal preference only.

HTH[/blue]

[code]
#include
#include

using namespace std;

int main()
{
int array[9] = { 0 };
double sales, //sales amount input by user
commission = 0.09, // 9 percent commission
pay = 200.00; // dollar amt paid to employee

for(;;)
{
cout << "Enter sales in dollars, -1 to end: "; //prompt for input
cin >> sales; // reads the sales dollars entered

if(sales == -1) break;

sales = sales * commission + pay; //pay calculation

cout << "Pay is: " << sales << endl; //gives the employees pay total

if(sales < 300)
array[0] += 1;

else if(sales < 400)
array[1] += 1;

else if(sales < 500)
array[2] += 1;

else if(sales < 600)
array[3] += 1;

else if(sales < 700)
array[4] += 1;

else if(sales < 800)
array[5] += 1;

else if(sales < 900)
array[6] += 1;

else if(sales < 1000)
array[7] += 1;

else
array[8] += 1;
}

cout << "Employees in the range:" << endl;

for(int i = 0; i < 8; ++i )
cout << endl << "\$ " << (i * 100 + 200) << '-' << (i * 100 + 299) << " - " << array[i];

cout << endl << "Over \$ 1000 - " << array[8];

return 0;

}[/code]
• Member Posts: 7
[green]Thanks for the ideas! It works except for the salary calculation which used to work. This is what I have at this point: [/green]

[code]
#include

using std::cout;
using std::cin;
using std::endl;

int main()
{

int cntarray[ 9 ] = { 0 };
int sales, //sales amount input by user
commission = .09, //9 percent commission
pay = 200.00; //dollar amt paid to employee

cout << "Enter sales in dollars, -1 to end input: "; //prompt for input
cin >> sales; // reads the input entered

while ( sales != -1 ) //sentinel value
{

{
sales = sales * commission + pay; //pay calculation

cout << "Pay is: " << sales <<endl; //gives the employees pay total

if( sales > 1 && sales <= 299 ) //start array calculations
{
cntarray[0]++;

}
else if( sales > 299 && sales <= 399 )
{
cntarray[1]++;

}
else if( sales > 399 && sales <= 499 )
{
cntarray[2]++;

}
else if( sales > 499 && sales <= 599 )
{
cntarray[3]++;

}
else if( sales > 599 && sales <= 699 )
{
cntarray[4]++;

}
else if( sales > 699 && sales <= 799 )
{
cntarray[5]++;

}
else if( sales > 799 && sales <= 899 )
{
cntarray[6]++;

}
else if( sales > 899 && sales <= 999 )
{
cntarray[7]++;

}
else if( sales > 999 )
{
cntarray[8]++;

}

cout << "Enter sales in dollars, -1 to end input: "; //prompt for input
cin >> sales; // reads the input entered
}

}

cout << "\$200-\$299: " << cntarray[0] << endl //calculates the entries
<< "\$300-\$399: " << cntarray[1] << endl
<< "\$400-\$499: " << cntarray[2] << endl
<< "\$500-\$599: " << cntarray[3] << endl
<< "\$600-\$699: " << cntarray[4] << endl
<< "\$700-\$799: " << cntarray[5] << endl
<< "\$800-\$899: " << cntarray[6] << endl
<< "\$900-\$999: " << cntarray[7] << endl
<< "\$1000 and over: " << cntarray[8] << endl;

return(0);

}

[/code]

: : Can someone please show me what i am doing wrong with my code? I have the salary calculation part but now i have to count the amount of salaries in the range.
:
: [blue]I didn't really look over the sales equation, but this *may* be what you're after. You don't really need an in between range case since the else paths will be followed. C/C++ array indexing uses [], 'AND' is &&, and THEN isn't required after if.
:
: Note: some things were changed for personal preference only.
:
: HTH[/blue]
:
: [code]
: #include <iostream>
: #include
:
: using namespace std;
:
: int main()
: {
: int array[9] = { 0 };
: double sales, //sales amount input by user
: commission = 0.09, // 9 percent commission
: pay = 200.00; // dollar amt paid to employee
:
: for(;;)
: {
: cout << "Enter sales in dollars, -1 to end: "; //prompt for input
: cin >> sales; // reads the sales dollars entered
:
: if(sales == -1) break;
:
: sales = sales * commission + pay; //pay calculation
:
: cout << "Pay is: " << sales << endl; //gives the employees pay total
:
: if(sales < 300)
: array[0] += 1;
:
: else if(sales < 400)
: array[1] += 1;
:
: else if(sales < 500)
: array[2] += 1;
:
: else if(sales < 600)
: array[3] += 1;
:
: else if(sales < 700)
: array[4] += 1;
:
: else if(sales < 800)
: array[5] += 1;
:
: else if(sales < 900)
: array[6] += 1;
:
: else if(sales < 1000)
: array[7] += 1;
:
: else
: array[8] += 1;
: }
:
: cout << "Employees in the range:" << endl;
:
: for(int i = 0; i < 8; ++i )
: cout << endl << "\$ " << (i * 100 + 200) << '-' << (i * 100 + 299) << " - " << array[i];
:
: cout << endl << "Over \$ 1000 - " << array[8];
:
: return 0;
:
: }[/code]
:

• Member Posts: 32
#include
#include // system pause funct for my compiler

using std::cout;
using std::cin;
using std::endl;
// using namespace std; is ok by itself

int main()
{
int cntarray[ 9 ] = { 0 };
const int pay = 200; //dollar amt paid to employee
double sales, //sales amount input by user
commission = .09; //9 percent commission
/* you screwed up again with the declarations -- sales should be decimal (float or double), not integer since e.g. 307*0.09=227.63, but as int it's still 227, you're stealing 63 cents from this one. Also, the commission cannot be an int of value 0.09, try to cout it.
Then, you put comma and go to the next line which is exactly what brought you to trouble of messing up.
Better to declare all variables in one line, or each separately on the new line to avoid confusion. Just a personal opinion
*/

cout << "Enter sales in dollars, -1 to end input: "; //prompt for input
cin >> sales; // reads the input entered
while ( sales != -1 ) //sentinel value
{
// why this extra brace?
/* I think the two lines below should go after comparing since you're comparing amount of sales, not the total pay which almost always yealds a value btw 200 and 300.
sales = sales * commission + pay; //pay calculation
cout << endl << "Pay is: " << sales <<endl; //gives the employees pay total
*/

/* a huge mistake below -- ever heard of short circuit evaluation?
Excelant observation by the poster above.
You say" if sales > 1 && .. " which most are -- then the second part of the expression (after &&) is not evaluated at all, that is, the processing stops there and the first element of the array is incremented regardless of the user's entry, and none of the other else if clauses are evaluated.
Sory, I was following your code so I didn't think of that.
*** you said:
if ( sales > 1 && sales <= 299 ) //start array calculations; totally wrong!
***
Although you can use the if/else clauses here in the manner the previous poster indicated by checking against the high bounds, you should not miss the opportunity to use a loop and get the advantage of the equal distances btw each value of the range from 200 to 1000 to ease the task.
*/
int i = 0;
while (i < 9) {
if (sales < ((i+1) * 100 + pay)) { // in first loop i=1*100+200=300 -- the first high bound
cntarray[i]++; // range 1 to 299 is incremented
i=9; // early exit
}
else {
i++; // increment i
} // end if
} // end while
sales = sales * commission + pay; //pay calculation; do with sales now what you want
cout << endl << "Pay is: " << sales <<endl; //gives the employees pay total

cout << "Enter sales in dollars, -1 to end input: "; //prompt for input
cin >> sales; // reads the input entered
} // end while

// } put always a comment after brace to indicate what block it ends; just personal

/* Again you could use a loop here to print out without doing it with many lines and printing each one separately.
Look at the code that the previous user provided for that purpose.
*/
cout << "\$200-\$299: " << cntarray[0] << endl //calculates the entries
<< "\$300-\$399: " << cntarray[1] << endl
<< "\$400-\$499: " << cntarray[2] << endl
<< "\$500-\$599: " << cntarray[3] << endl
<< "\$600-\$699: " << cntarray[4] << endl
<< "\$700-\$799: " << cntarray[5] << endl
<< "\$800-\$899: " << cntarray[6] << endl
<< "\$900-\$999: " << cntarray[7] << endl
<< "\$1000 and over: " << cntarray[8] << endl;

system("PAUSE");
return(0);
} // end main

This now works for sure if it is what you are looking for.
rgds
fuel730

: [green]Thanks for the ideas! It works except for the salary calculation which used to work. This is what I have at this point: [/green]
:
: [code]
: #include <iostream>
:
: using std::cout;
: using std::cin;
: using std::endl;
:
:
: int main()
: {
:
:
:
: int cntarray[ 9 ] = { 0 };
: int sales, //sales amount input by user
: commission = .09, //9 percent commission
: pay = 200.00; //dollar amt paid to employee
:
:
:
: cout << "Enter sales in dollars, -1 to end input: "; //prompt for input
: cin >> sales; // reads the input entered
:
: while ( sales != -1 ) //sentinel value
: {
:
: {
: sales = sales * commission + pay; //pay calculation
:
: cout << "Pay is: " << sales <<endl; //gives the employees pay total
:
:
: if( sales > 1 && sales <= 299 ) //start array calculations
: {
: cntarray[0]++;
:
: }
: else if( sales > 299 && sales <= 399 )
: {
: cntarray[1]++;
:
: }
: else if( sales > 399 && sales <= 499 )
: {
: cntarray[2]++;
:
: }
: else if( sales > 499 && sales <= 599 )
: {
: cntarray[3]++;
:
: }
: else if( sales > 599 && sales <= 699 )
: {
: cntarray[4]++;
:
: }
: else if( sales > 699 && sales <= 799 )
: {
: cntarray[5]++;
:
: }
: else if( sales > 799 && sales <= 899 )
: {
: cntarray[6]++;
:
: }
: else if( sales > 899 && sales <= 999 )
: {
: cntarray[7]++;
:
: }
: else if( sales > 999 )
: {
: cntarray[8]++;
:
:
: }
:
: cout << "Enter sales in dollars, -1 to end input: "; //prompt for input
: cin >> sales; // reads the input entered
: }
:
: }
:
: cout << "\$200-\$299: " << cntarray[0] << endl //calculates the entries
: << "\$300-\$399: " << cntarray[1] << endl
: << "\$400-\$499: " << cntarray[2] << endl
: << "\$500-\$599: " << cntarray[3] << endl
: << "\$600-\$699: " << cntarray[4] << endl
: << "\$700-\$799: " << cntarray[5] << endl
: << "\$800-\$899: " << cntarray[6] << endl
: << "\$900-\$999: " << cntarray[7] << endl
: << "\$1000 and over: " << cntarray[8] << endl;
:
:
: return(0);
:
: }
:
: [/code]
:
:
: : : Can someone please show me what i am doing wrong with my code? I have the salary calculation part but now i have to count the amount of salaries in the range.
: :
: : [blue]I didn't really look over the sales equation, but this *may* be what you're after. You don't really need an in between range case since the else paths will be followed. C/C++ array indexing uses [], 'AND' is &&, and THEN isn't required after if.
: :
: : Note: some things were changed for personal preference only.
: :
: : HTH[/blue]
: :
: : [code]
: : #include <iostream>
: : #include
: :
: : using namespace std;
: :
: : int main()
: : {
: : int array[9] = { 0 };
: : double sales, //sales amount input by user
: : commission = 0.09, // 9 percent commission
: : pay = 200.00; // dollar amt paid to employee
: :
: : for(;;)
: : {
: : cout << "Enter sales in dollars, -1 to end: "; //prompt for input
: : cin >> sales; // reads the sales dollars entered
: :
: : if(sales == -1) break;
: :
: : sales = sales * commission + pay; //pay calculation
: :
: : cout << "Pay is: " << sales << endl; //gives the employees pay total
: :
: : if(sales < 300)
: : array[0] += 1;
: :
: : else if(sales < 400)
: : array[1] += 1;
: :
: : else if(sales < 500)
: : array[2] += 1;
: :
: : else if(sales < 600)
: : array[3] += 1;
: :
: : else if(sales < 700)
: : array[4] += 1;
: :
: : else if(sales < 800)
: : array[5] += 1;
: :
: : else if(sales < 900)
: : array[6] += 1;
: :
: : else if(sales < 1000)
: : array[7] += 1;
: :
: : else
: : array[8] += 1;
: : }
: :
: : cout << "Employees in the range:" << endl;
: :
: : for(int i = 0; i < 8; ++i )
: : cout << endl << "\$ " << (i * 100 + 200) << '-' << (i * 100 + 299) << " - " << array[i];
: :
: : cout << endl << "Over \$ 1000 - " << array[8];
: :
: : return 0;
: :
: : }[/code]
: :
:
:

• Member Posts: 7
[green]Woo Hoo! I got it! You guys are the best! Thanks so much for all your help [/green]

: #include
: #include // system pause funct for my compiler
:
: using std::cout;
: using std::cin;
: using std::endl;
: // using namespace std; is ok by itself
:
: int main()
: {
: int cntarray[ 9 ] = { 0 };
: const int pay = 200; //dollar amt paid to employee
: double sales, //sales amount input by user
: commission = .09; //9 percent commission
: /* you screwed up again with the declarations -- sales should be decimal (float or double), not integer since e.g. 307*0.09=227.63, but as int it's still 227, you're stealing 63 cents from this one. Also, the commission cannot be an int of value 0.09, try to cout it.
: Then, you put comma and go to the next line which is exactly what brought you to trouble of messing up.
: Better to declare all variables in one line, or each separately on the new line to avoid confusion. Just a personal opinion
: */
:
: cout << "Enter sales in dollars, -1 to end input: "; //prompt for input
: cin >> sales; // reads the input entered
: while ( sales != -1 ) //sentinel value
: {
: // why this extra brace?
: /* I think the two lines below should go after comparing since you're comparing amount of sales, not the total pay which almost always yealds a value btw 200 and 300.
: sales = sales * commission + pay; //pay calculation
: cout << endl << "Pay is: " << sales <<endl; //gives the employees pay total
: */
:
: /* a huge mistake below -- ever heard of short circuit evaluation?
: Excelant observation by the poster above.
: You say" if sales > 1 && .. " which most are -- then the second part of the expression (after &&) is not evaluated at all, that is, the processing stops there and the first element of the array is incremented regardless of the user's entry, and none of the other else if clauses are evaluated.
: Sory, I was following your code so I didn't think of that.
: *** you said:
: if ( sales > 1 && sales <= 299 ) //start array calculations; totally wrong!
: ***
: Although you can use the if/else clauses here in the manner the previous poster indicated by checking against the high bounds, you should not miss the opportunity to use a loop and get the advantage of the equal distances btw each value of the range from 200 to 1000 to ease the task.
: */
: int i = 0;
: while (i < 9) {
: if (sales < ((i+1) * 100 + pay)) { // in first loop i=1*100+200=300 -- the first high bound
: cntarray[i]++; // range 1 to 299 is incremented
: i=9; // early exit
: }
: else {
: i++; // increment i
: } // end if
: } // end while
: sales = sales * commission + pay; //pay calculation; do with sales now what you want
: cout << endl << "Pay is: " << sales <<endl; //gives the employees pay total
:
: cout << "Enter sales in dollars, -1 to end input: "; //prompt for input
: cin >> sales; // reads the input entered
: } // end while
:
: // } put always a comment after brace to indicate what block it ends; just personal
:
: /* Again you could use a loop here to print out without doing it with many lines and printing each one separately.
: Look at the code that the previous user provided for that purpose.
: */
: cout << "\$200-\$299: " << cntarray[0] << endl //calculates the entries
: << "\$300-\$399: " << cntarray[1] << endl
: << "\$400-\$499: " << cntarray[2] << endl
: << "\$500-\$599: " << cntarray[3] << endl
: << "\$600-\$699: " << cntarray[4] << endl
: << "\$700-\$799: " << cntarray[5] << endl
: << "\$800-\$899: " << cntarray[6] << endl
: << "\$900-\$999: " << cntarray[7] << endl
: << "\$1000 and over: " << cntarray[8] << endl;
:
: system("PAUSE");
: return(0);
: } // end main
:
:
: This now works for sure if it is what you are looking for.
: rgds
: fuel730
:
:
: : [green]Thanks for the ideas! It works except for the salary calculation which used to work. This is what I have at this point: [/green]
: :
: : [code]
: : #include <iostream>
: :
: : using std::cout;
: : using std::cin;
: : using std::endl;
: :
: :
: : int main()
: : {
: :
: :
: :
: : int cntarray[ 9 ] = { 0 };
: : int sales, //sales amount input by user
: : commission = .09, //9 percent commission
: : pay = 200.00; //dollar amt paid to employee
: :
: :
: :
: : cout << "Enter sales in dollars, -1 to end input: "; //prompt for input
: : cin >> sales; // reads the input entered
: :
: : while ( sales != -1 ) //sentinel value
: : {
: :
: : {
: : sales = sales * commission + pay; //pay calculation
: :
: : cout << "Pay is: " << sales <<endl; //gives the employees pay total
: :
: :
: : if( sales > 1 && sales <= 299 ) //start array calculations
: : {
: : cntarray[0]++;
: :
: : }
: : else if( sales > 299 && sales <= 399 )
: : {
: : cntarray[1]++;
: :
: : }
: : else if( sales > 399 && sales <= 499 )
: : {
: : cntarray[2]++;
: :
: : }
: : else if( sales > 499 && sales <= 599 )
: : {
: : cntarray[3]++;
: :
: : }
: : else if( sales > 599 && sales <= 699 )
: : {
: : cntarray[4]++;
: :
: : }
: : else if( sales > 699 && sales <= 799 )
: : {
: : cntarray[5]++;
: :
: : }
: : else if( sales > 799 && sales <= 899 )
: : {
: : cntarray[6]++;
: :
: : }
: : else if( sales > 899 && sales <= 999 )
: : {
: : cntarray[7]++;
: :
: : }
: : else if( sales > 999 )
: : {
: : cntarray[8]++;
: :
: :
: : }
: :
: : cout << "Enter sales in dollars, -1 to end input: "; //prompt for input
: : cin >> sales; // reads the input entered
: : }
: :
: : }
: :
: : cout << "\$200-\$299: " << cntarray[0] << endl //calculates the entries
: : << "\$300-\$399: " << cntarray[1] << endl
: : << "\$400-\$499: " << cntarray[2] << endl
: : << "\$500-\$599: " << cntarray[3] << endl
: : << "\$600-\$699: " << cntarray[4] << endl
: : << "\$700-\$799: " << cntarray[5] << endl
: : << "\$800-\$899: " << cntarray[6] << endl
: : << "\$900-\$999: " << cntarray[7] << endl
: : << "\$1000 and over: " << cntarray[8] << endl;
: :
: :
: : return(0);
: :
: : }
: :
: : [/code]
: :
: :
: : : : Can someone please show me what i am doing wrong with my code? I have the salary calculation part but now i have to count the amount of salaries in the range.
: : :
: : : [blue]I didn't really look over the sales equation, but this *may* be what you're after. You don't really need an in between range case since the else paths will be followed. C/C++ array indexing uses [], 'AND' is &&, and THEN isn't required after if.
: : :
: : : Note: some things were changed for personal preference only.
: : :
: : : HTH[/blue]
: : :
: : : [code]
: : : #include <iostream>
: : : #include
: : :
: : : using namespace std;
: : :
: : : int main()
: : : {
: : : int array[9] = { 0 };
: : : double sales, //sales amount input by user
: : : commission = 0.09, // 9 percent commission
: : : pay = 200.00; // dollar amt paid to employee
: : :
: : : for(;;)
: : : {
: : : cout << "Enter sales in dollars, -1 to end: "; //prompt for input
: : : cin >> sales; // reads the sales dollars entered
: : :
: : : if(sales == -1) break;
: : :
: : : sales = sales * commission + pay; //pay calculation
: : :
: : : cout << "Pay is: " << sales << endl; //gives the employees pay total
: : :
: : : if(sales < 300)
: : : array[0] += 1;
: : :
: : : else if(sales < 400)
: : : array[1] += 1;
: : :
: : : else if(sales < 500)
: : : array[2] += 1;
: : :
: : : else if(sales < 600)
: : : array[3] += 1;
: : :
: : : else if(sales < 700)
: : : array[4] += 1;
: : :
: : : else if(sales < 800)
: : : array[5] += 1;
: : :
: : : else if(sales < 900)
: : : array[6] += 1;
: : :
: : : else if(sales < 1000)
: : : array[7] += 1;
: : :
: : : else
: : : array[8] += 1;
: : : }
: : :
: : : cout << "Employees in the range:" << endl;
: : :
: : : for(int i = 0; i < 8; ++i )
: : : cout << endl << "\$ " << (i * 100 + 200) << '-' << (i * 100 + 299) << " - " << array[i];
: : :
: : : cout << endl << "Over \$ 1000 - " << array[8];
: : :
: : : return 0;
: : :
: : : }[/code]
: : :
: :
: :
:
:

• Member Posts: 32
Let me correct myself on the short circuit evaluation:
In the case of an (&&) AND logical operator the evaluation continues only if the previous expression returns true.
int c = 10;
if ((c > 1) // returns true, thus it continues looking for a false or the end of the statement to fall out
&& (c < 8)) { // returns false, thus making the whole statement false; here evaluation stops.
// It would have been true if c was 7.
In the case of an (||) OR logical operator, as soon as any expression of a statement is true, the whole statement becomes true, and at that point the evaluation stops, or it continues to the end of a statement.
if ((c > 1) // true, evaluation finished
|| (c < 8)) { // this part is not evaluated; it would have been if c was 0.

Just to make it clear.
fuel730