Function Trouble

I wrote a program that is suppose to get two integers between the parameters. The second number needs to be between the (first # +1) and 20. The problem is the second number always outputs: Enter box width (between 0 and 20). I am new to c++ and I feel this is a simple fix that I'm just not seeing. Any help would be great.

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
39
40
41
42
43
#include <iostream>
#include <limits>

using namespace std;

int getInteger(int low, int high);

int main() {
   
    int boxHeight;
    int boxWidth;
    
    cout << "Enter box height (between 3 and 10): ";
    boxHeight = getInteger(3, 10);
    
    cout << "Enter box width (between " << boxHeight << " and 20): ";
    boxWidth = getInteger(boxHeight + 1, 20);


    
    
}

int getInteger(int low, int high){
    
    int num;
    
    cin >> num;
    cin.clear();
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    
    while (num < low || num > high){
        cout << "please try again: ";
        cin >> num;
        cin.clear();
        cin.ignore(numeric_limits<streamsize>::max(), '\n');
    }
    cout << endl;
    
    return 0;
    
}
Never mind, I figured it out. It should be: return num; at the bottom of the code.
Hello gtrruff,

If you are finished put a green check mark on the subject so that everyone knows that you are finished.

Andy
Topic archived. No new replies allowed.