C2601

I am working with the following pseudocode:

Using the pseudocode below, write the code that will meet the requirements.

Declare constants SIZE and MIN
Function prototype for isValid
Main Function

Declare the password as a character array.
While true
Display the password requirements
Get password from user
Call the isValid function
Display results of isValid function

isValid function
Declare Boolean variables
Use strlen command to determine the length of the password and if it is greater than MIN, set bool value to true
Loop
Test if password has a lowercase letter
Test if password has an upperecase letter
Test if password has a digit
Go to next character (ie *password++;)
End loop
If all boolean values are true, return 1, else return 0

And I am getting the error C2601 'isValid': local function definitions are illegal.


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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "stdafx.h"
#include <iostream>
#include <cstring>

using namespace std;


//Declare constants SIZE and MIN
const int SIZE = 80;
const int MIN = 0;
int length;

//Function prototype for isValid
int isValid();
//Main Function
int main()
{

	//Declare the password as a character array 
	char password[80];

	//While true
	while (true)
	{
		//Display the password requirements
		cout << "Password Requirements: " << endl;
		cout << "- The password should be at least 6 characters long " << endl;
		cout << "- The password should contain at least one uppercase " << endl;
		cout << "- and one lowercase letter" << endl;
		cout << "- The password should have at least one digit" << endl;
		//Get password from user
		cout << "Enter a password: " << endl;
		cin >> password;
		//Call the isValid function
		cout << " " << isValid();
		//Display results of isValid function
		cout << " \n";


//isValid function
int isValid()
{
	//Declare Boolean variables
	bool isValid = true;
	//Use strlen command to determine the length of the password 
	//and if it is greater than MIN, set bool value to true
	length = strlen(password);

	//Loop
	for (i = 0; i < password; i++)
	{
		//Test if password has a lowercase letter
		if (islower(*password))
		{

		}
		//Test if password has an upperecase letter
		if (isupper(*password))
		{

		}
		//Test if password has a digit
		if (isdigit(*password))
		{

		}
		//Go to next character(ie *password++;)
		//End loop
	}
    //If all boolean values are true, return 1, else return 0 


	
}


	}
}
Last edited on
You can't define a function inside another function definition.
Move isValid to after main.
Your function isValid is inside your function main. Don't put functions inside each other. Finish main, then write isValid.
Okay, I moved the isValid function outside of the main function. Is anyone able to help me on the strlen command?


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
44
45
46
47
48
49
#include "stdafx.h"
#include <iostream>
#include <cstring>

using namespace std;

int isValid();

//Declare constants SIZE and MIN
const int SIZE = 80;
const int MIN = 0;
int length;

//Function prototype for isValid

//Main Function
int main()
{

	//Declare the password as a character array 
	char password[80];

	//While true
	while (true)
	{
		//Display the password requirements
		cout << "Password Requirements: " << endl;
		cout << "- The password should be at least 6 characters long " << endl;
		cout << "- The password should contain at least one uppercase " << endl;
		cout << "- and one lowercase letter" << endl;
		cout << "- The password should have at least one digit" << endl;
		//Get password from user
		cout << "Enter a password: " << endl;
		cin >> password;
		//Call the isValid function
		cout << " " << isValid();
	}
		//Display results of isValid function
		
		
	
}

int isValid()
{
	//Declare Boolean variables 
	bool isValid = true;
	//Use strlen command to determine the length of the password 
	//and if it is greater than MIN, set bool value to true 
Topic archived. No new replies allowed.