-999 ?

Feb 24, 2010 at 8:53pm
Ok I'm reading my C++ book I got in college, I'm on chapter 8, about 500 pages in. The book is talking about a program that calculates grades from 2 input files then outputs them back to a file. It uses

1
2
3

while (score != -999)


my question, what is the significance of -999 ? I know it must be the return of something, a error from something or whatever, i just can't remember what.
Feb 24, 2010 at 8:59pm
Probably just a "magic number" that escapes the loop.

The number itself has no significance other than that it's used to exit the loop. The program probably explicitly sets score to -999 somewhere when it wants the loop to stop.

It's unclear (hence your quesiton), which is why usage of magic numbers is not recommended.
Feb 24, 2010 at 9:19pm
I guess it was supposed to be a sentinel controlled while loop
Feb 25, 2010 at 3:17am
.........meaning that somewhere within the loop body there will be a direction:
1
2
cout<<"Enter a number n  (-999 to quit);
cin>>n; 
Topic archived. No new replies allowed.