Validating password

So this is my code that I have made, I know there is something wrong with this and I figure it might be my int get_int function. I am stuck an I don't know how to proceed to return a value back and have it ask the prompt depending it its the upper, lower ,or length


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
 int get_int(char prompt[], int min, int max);
 12 int validate_password(char pwd[], int min_uppers,
 13                       int min_lowers, int min_length);
 14 int main()
 15 {
 16     char password[20];
 17     int min_uppers, min_lowers, min_length;
 18
 19     min_uppers = get_int("How many upper case characters are
 20                           required? ", 1, 3);
 21     min_lowers = get_int("How many lower case characters are
 22                           required? ", 1, 3);
 23     min_length = get_int("What is minimum length (6-8)? ", 6, 8);
 24
 25     cout << endl << endl;
 26
 27     cout << "OK\n";
 28     cout <<"Enter your password: ";
 29     cin.getline(password,20);
 30
 int get_int(char prompt[], int min, int max)
 64 {
 65     int value;
 66     value = min;
 67     value = max;
 68
 69     if(value >= 1 && value <= 3)
 70     return value;
 71     else
 72     value = get_int(": NUMBER MUST BE WITHIN RANGE\n"
 73
 74 }


Output:


How many uppers required (1-3)? 2
How many lowers required (1-3)? 1
What is the minimum length (6-8)? 5
: NUMBER MUST BE WITHIN RANGE
What is the minimum length (6-8)? 6
Last edited on
The output you have showed cannot be generated by the code you showed. Please try not to do that; if you show code and output, the output shown should be from the code that was shown.

Looks like you need your get_int function to loop until the input is acceptable. Do NOT have your get_int function call itself again.

http://www.cplusplus.com/doc/tutorial/control/
Last edited on
Your get_int() function needs to do several things:

- get an integer input by the user (so you will be using cin)
- check whether the input value is within the range specified by your arguments (min and max)
- keep looping WHILE it doesn't satisfy this

Definitely follow up Moschops' link. Think out the logic in words/pseudocode before coding.
Topic archived. No new replies allowed.