### Help: program giving me unlimited loop

I just completed my program then I decided to debug it. When the program begin, it keeps outputting the message infinitely. I don't understand what's the problem.

Here's my program.
 ```// weekgrosssales.cpp #include #include using namespace std; // Begin main function execution int main() { const int sales = 10; int counter = 0; // Initialize counter int totalsales; // Initialize totalsales int group1 = 0, group2 = 0, group3 = 0, group4 = 0, group5 = 0, group6 = 0, group7 = 0, group8 = 0, group9 = 0; // Initialize all group for the bar chart int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0; int salesperson[sales]; // The formulae for totalsales totalsales = 200 + (sales * 9/100 ); // Counter while ( counter < 10 ) cout << "Please enter your weekly sales"; cin >> salesperson[sales]; // To determine which group the totalsales should be placed if (sales >= 200 && sales < 300) // if totalsales is between \$200-\$299 { ++group1; // increment group1 ++counter; // increment counter } if (sales >= 300 && sales < 400) // if totalsales is between \$300-\$399 { ++group2; // increment group2 ++counter; // increment counter } if (sales >= 400 && sales < 500) // if totalsales is between \$400-\$499 { ++group3; // increment group3 ++counter; // increment counter } if (sales >= 500 && sales < 600) // if totalsales is between \$500-\$599 { ++group4; // increment group4 ++counter; // increment counter } if (sales >= 600 && sales < 700) // if totalsales is between \$600-\$699 { ++group5; // increment group5 ++counter; // increment counter } if (sales >= 700 && sales < 800) // if totalsales is between \$700-\$799 { ++group6; // increment group6 ++counter; // increment counter } if (sales >= 800 && sales < 900) // if totalsales is between \$800-\$899 { ++group7; // increment group7 ++counter; // increment counter } if (sales >= 900 && sales < 1000) // if totalsales is between \$900-\$999 { ++group8; // increment group8 ++counter; // increment counter } if (sales >= 1000 ) // if totalsales is over or equal to \$1000 { ++group9; // increment group9 ++counter; // increment counter } else // if it doesn't satisfy any criteria { ++counter; // increment counter cout << "The following weekly gross sales is ignored" << endl; } // For the bar chart cout << "\$200-\$299"; while (a <= group1) cout << "*"; cout << "\$300-\$399"; while (b <= group2) cout << "*"; cout << "\$400-\$499"; while (c <= group3) cout << "*"; cout << "\$500-\$599"; while (d <= group4) cout << "*"; cout << "\$600-\$699"; while (e <= group5) cout << "*"; cout << "\$700-\$799"; while (f <= group6) cout << "*"; cout << "\$800-\$899"; while (g <= group7) cout << "*"; cout << "\$900-\$999"; while (h <= group8) cout << "*"; cout <<"\$1000 and above"; while (i <= group9) cout << "*"; }```
What is it a stupid code?
You defined sales as

const int sales = 10;

Then you wrote

if (sales >= 200 && sales < 300)

Please explain me how can sales be greater than or equal to 200?

Also where is inputed data written in this statement

cin >> salesperson[sales];

 ``12`` `````` while (a <= group1) cout << "*";``````
The problem is that neither `a` nor `group1` will ever change, hence you have either no loop at all or an infinite loop
I'll do another program with scratch and delete this programme.
Topic archived. No new replies allowed.