end of semester crunch time and i need help

This program builds an array for sales people 1-10. The user enters the salesperson number and then enters the sales amount. Each salesperson may have multiple sales transactions or none. The users enters 99 (as the bogus salesperson number) to stop the program. The program displays each salesperson number and the total of the sales amounts enters.
the problem is it just goes into a constant loop
#include<iostream>
using namespace std;

int main()
{
const int SIZE = 10;
double earnings[SIZE];
const int STOP = 99;
double amt;
int person;
cout << "Enter sales made by any of our ten salespeople" << endl <<
"Their sales numbers are digits 1 through 10" << endl <<
"You can enter as many money amounts as you want " << endl <<
"for each person in any order" << endl;
cout << "Enter salesperson number 1 - " << SIZE << ". Enter " << STOP << " to quit. ";
cin >> person;
while(person = STOP)
{
if(person >= 1 && person <= 10)
{
cout << "Enter the sale amount ";
cin >> amt;
earnings[person-1] += amt;
}
else
cout << "Number out of range. Please enter another" << endl;
cout << "Enter another salesperson number 1 - SIZE or STOP to quit ";
cin >> person;
}
cout << endl << "Salesperson totals are:" << endl;
for(person = 0; person < SIZE; --person)
cout << "Salesperson " << (person + 1) << " $" << earnings[person] << endl;
return 0;
}
 
while(person = STOP)

is always true so the loop will run forever
I'm guessing you meant
 
while(person == STOP)

or
 
while(person != STOP)
Immediately your problem is obvious

while((person = STOP)) //You need double brackets to make it a condition
This will assign the value of 99 to the variable person and since 99 is not zero, this will evaluate as true for the loop and it will loop forever

What you want to do is:

while(person != STOP)
Last edited on
Topic archived. No new replies allowed.