Program takes one number and then does nothing

The below builds without errors, however the issue is when it is running and it take 1 number and then doesn't do anything else. I am trying to write a program that gets a user's input for a number and displays the maximum and minimum values and continues until a user enters -99.

1 #include <iostream>
2 #include <cstdlib>
3 #include <math.h>
4 using namespace std;
5
6 void whileNum(int &num, int &smallest, int &largest);
7
8 //initiate main
9 int main()
10 {//open main()
11
12 //establish integers
13 int num;
14 int smallest=0;
15 int largest=0;
16
17 whileNum(num, smallest, largest);
18
19 system("Pause");
20 return 0;
21 }//close main()
22
23 void whileNum(int &num, int &smallest, int &largest)
24
25 {
26 cout << "Enter a number or -99 to QUIT" << endl;
27 cin>> num;
28 while (num != -99);
29 {//open while()
30
31
32
33 //if statements for maximum and minimum
34 if (num>=largest)
35 largest=num;
36 if (num<=smallest)
37 smallest=num;
38
39 //display largest and smallest values
40 cout << "Largest: " << largest << " Smallest: " << smallest << 41 endl;
42
43 }//close while()
44
45 num=-99;
46 cout <<"Good-bye" << endl;
47
48 }
49
Hi,

cin>>num; should be inside the while loop, otherwise it will not will be evaluated again after its execution

PS: please use code tags

http://www.cplusplus.com/articles/jEywvCM9/
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/193388/

Please use code tags and avoid double posts
Topic archived. No new replies allowed.