Hi,

I was hoping that someone could give me some direction with how to solve this probem.

The only info in this problem is
word has N digits[only digits] and
each digit in the word is in increasing order example 1469 or 362

I have to verify if the number I enter matches the above restrictions.

Thanks,
Cathy

Read your book / course notes on the 'if' statement, and post an attempt.

``````//assuming digits are not repeated
//For a well formed password of length N the last digit  has to be  N <= i <= 9
//Ex:: N = 5 last digit has to be greates than 5 --> 12346 is a good password whereas 12354 is not

bool void PassWordTest ( int number, int length )   //true if pass

{

int  tempnum = number;

for (int i = N ;i >0 ; i -- )
{
int tempdig = tempnum%10;
if(tempdig < i  )
return false;
else
tempnum /= tempnum ;  //remove last dig and continue
}

return true;

}

//same can be done using recursion``````

1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) on the background of the box you actually typed your message in
to learn how to use code tags. It's not like the information isn't available and in your face. It's really hard to miss.

commented: You forgot to add "don't provide complete answers on a plate in response to zero effort" +22
commented: yup +17
``````//CORRECTED CODE

//assuming digits are not repeated
//For a well formed password of length N the last digit  has to be  N <= i <= 9
//Ex:: N = 5 last digit has to be greates than 5 --> 12346 is a good password whereas 12354 is not

bool PassWordTest ( int number, int N )   //true if pass

{

int  tempnum = number;

for (int i = N ;i >0 ; i -- )
{
int tempdig = tempnum%10;
if(tempdig < i  )
return false;
else
tempnum /= tempnum ;  //remove last dig and continue
}

return true;

}

//same can be done using recursion``````

I am not sure. But

``tempnum /= tempnum ;``

You are dividing a number by itself which would result in being one right.
I think it should be

``tempnum= (tempnum-tempdig)/10;``

This way the last digit can be removed .
If that is what you want to do.

Its actually tempnum /= 10 ...sorry..my bad..

``````//Thanks for your response.
//Though the solution would work well in certain cases it wouldn't work if N=5 and the number id 4582

//This is what I feel. Please let me know if there is a mistake.

bool PassWordTest ( int num, int N ) //true if pass
{
int number = num;
for (int i = N ;i >0 ; i -- )
{
int remainder = number%10;
number /= 10; //removing the last dig and continue
int new_remainder = number%10;

if(new_remainder > remainder )
return false;

}
return true;
}``````

>>is word has N digits[only digits] and each digit in the word is in increasing order example 1469 or 362

First, should that be 236 instead of 362?

Second, what if word is a string rather than an int? When I think of word I think of string, not int.

Third, how do you plan to determine/calculate the value of N in the following?

bool PassWordTest ( int num, int N ) //true if pass
for (int i = N ;i >0 ; i -- )

or will all words have the same value of N?

>>is word has N digits[only digits] and each digit in the word is in increasing order example 1469 or 362

First, should that be 236 instead of 362?
Oh ! that's a mistake, your right, it should be 236.
Second, what if word is a string rather than an int? When I think of word I think of string, not int.
This problem is realted to numbers only

Third, how do you plan to determine/calculate the value of N in the following?

bool PassWordTest ( int num, int N ) //true if pass
for (int i = N ;i >0 ; i -- )

or will all words have the same value of N?
Yes, I plan on comparing that in a seperate, if statement but I didn't want to include that in the code as it would look to lenghty in this forum

Thanks,
Cathy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.