'while' looping

My SENTINEL value of "-99" operates just fine, however when I enter in numbers, using a space in between, and finally press the "ENTER" key, nothing happens. What I am trying to accomplish is:
a) store 'x' amount of numbers a user enters
b) determine the smallest number of those 'x' amount of numbers
c) output the smallest number to the user's display device

...the rest of my program runs smoothly and as such, I've left out code for the non-relevant area; ease of reading.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#include <iostream>
#include <iomanip>

using namespace std;

const int menuChoiceB_SENTINEL = -99; // Terminates 'while' loop under Menu Choice 'b'//

	// Start of Main program //
int main()
{	// Start of Main //
  int smallNum, smallestNum;
  int nextSmallNum = ' ';

else if (menuChoice == 'b')
{ // start "menu" if //
 system ("CLS");
 cout << "Menu Choice 'b'\n"
 << "Please enter any amount of numbers, using a space between each number.\n"
 << "Entering ''-99'' (without quotes) will return you to the 'Main Menu'.\n" << endl;

cin >> smallNum;

smallestNum = smallNum;
				
  while (nextSmallNum != menuChoiceB_SENTINEL)
  { // start while //
    cin >> nextSmallNum;
  } // endwhile //

   if (smallestNum > nextSmallNum && nextSmallNum != menuChoiceB_SENTINEL) 
   { // start if //
     smallestNum = nextSmallNum;
     cout << "The smallest number entered was: " <<endl; 
     cout << smallestNum << endl; 
   } // end if //

} // end "menu" if // 
Last edited on
The problem lies in the scope of your while loop
Topic archived. No new replies allowed.