Term does not evaluate to a function taking 1 arguments??

Hello,

I have prepared a code for my homework assignment in my intro to programming class. I had to write a program the requests a password and verifies that it is valid. To be valid the password must be 6 characters long and contain at least 1 digit. I almost have it finished, but I keep getting the same error on Line (27): Error C2064: term does not evaluate to a function taking 1 arguments.. I have fixed all the other errors, but I cannot get the program to compile. I would appreciate any assistance or an extra set of eyes to point me in the right direction. Here is my code below:

#include <iostream>

using namespace std;
int main()
{

int Password;
int Length;
int Index;
int validPassword;

while (1)
{
cout << "Please enter your password:" << endl;
cin >> Password;
validPassword =false;
Length =Password;
if (Length<6)
{
cout << "Your password should be at least 6 characters long" << endl; }
else
{
Index =1;
while (1)
{
if(Password(Index)>='0' && Password(Index)<='9') Here is the ERROR.
{
validPassword =true;
}
else
{
Index =Index+1;
}
if (validPassword=true || Index>Length) break;
}
if (validPassword=true)
{
cout << "Thank you, that is a valid Password!" << endl; }
else
{
cout << "Your password must include at least one digit (1-9)" << endl; }
}
if (validPassword=true) break;
}

return 0;
}
validPassword=true
Did you mean validPassword==true? maybe you did, maybe you didn't. I think you don't really know what you're doing here.

Setting an int to the value true or false is..... unconventional. If you want something limited to true and false, use bool. It will confuse people less.

1
2
3
Length =Password;
if (Length<6)
cout << "Your password should be at least 6 characters long" << endl; }

This is just crazy. The variable length here is NOT the length of the variable password. It's just the same value as password. Calling a variable length does not magically make it the length of some other variable.

Password(Index)
Here, you are trying to call a function named Password that takes a single parameter of type int. No such function exists.

It seems that you're just trying to guess how to program in C++. That's not going to work. You're going to have to learn first.
Last edited on
Password(Index) - this is attempting to call a function called Password().

If Password was a string, you could use Password[Index] to access individual characters (square brackets!). But since it's an integer, that won't work either.

I suggest you change it to be a string.

Also, this line if (validPassword=true) break; should use ==, not =.

One more thing. Please use [code]your code here[/code] tags.


Last edited on
Not only what the above have stated, but Password is declared as type int as well. Either this forces you to convert all char to ints, or to only enter integers are your password. Since you have included code to check to see if at least one of char is a digit, I'm assuming you at least used the wrong type for Password and instead wanted to use char.

Also, it helps alot to used the code tags. That's alot of brackets in there that are near unreadable. :)

Now if Password should include alphabetic chars, then Password should either be type char[] which is a char array, or a string object (which you'll need to #include <string> to use).

With either there's a function that will return the length of Password as such:

length = strlen(Password);

This code assumes 2 things. 1) That you already declared length as type int (since that's what strlen returns) and 2) that Password is declared as a type char[] (or char array). Then you can use the if (Length < 6)

If you are using a string for Password you would do this:

1
2
3
 string Password;
// cin and stuff here
Length = Password.length();


.length is a member function of the string object and returns the number of chars the string contains.

Last, like the others have said, not exactly sure what you are trying to do with the if(Password(Index) lines, or why you'd want to set validPassword to true if the character at (index) falls between 0 and 9. In fact, now that I think of it, even if you used a number only password you'd STILL have to use a char array or string because there's no way to iterate through the different digits of an integer (or any other numeric type) that I'm aware of. So either way, Password is going to have to be a char array or a string.

Last edited on
Topic archived. No new replies allowed.