Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Pseudocode problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
NEOS




PostPosted: Sun Dec 07, 2008 5:48 pm   Post subject: Pseudocode problem

This is my code and I just need to know if that's how I make it ask for the password 5 times, using the for loop.

% Write a pseudocode for a program that checks to see if a password is valid.
% The criteria for the password are listed below. The user must enter in the
% password and a message must be given if the password is valid or invalid.
% If it is invalid the program must allow the user to enter in a new one;
% and again, up to 5 times.
Turing:

/*
 Variables password : String
 For i : 1..5
 Get password

 Function Capletter (Cap:Int)
 Check the ASCII Code Of password(1),password(2),password(3),password(4),password(5),password(6),password(7),password(8),password(9),password(10),password(11),password(12)
 If The ASCII Of each Letter Equals Between 65 And 90 Then
 Display Password is Valid Message
 Else
 Display Password is Invalid Message
 The Result is If The password has at least one ASCII code
 End Capletter

 Function Oneletter (Lett:Int)
 If the ASCII code For password (1) Equals Between 65 And 90, 97 And 122 Then
 Display Password is Valid Message
 Else
 Display Password is Invalid Message
 The Result is If The password has at least one ASCII code
 End Oneletter

 Function Onepun (pun:Int)
 If the ASCII code For password (1) Equals Between 33, 63, 46 Then
 Display Password is Valid Message
 Else
 Display Password is Invalid Message
 The Result is If The password has at least one ASCII code
 End Onepun

 Function Onenum (num:Int)
 If the ASCII code For password (1) Equals Between 48 And 57 Then
 Display Password is Valid Message
 Else
 Display Password is Invalid Message
 The Result is If The password has at least one ASCII code
 End Onenum

 If the Password Does not Have a Puncuation mark, One letter, one Number, a Capital letter, At Least 6 charecters And A max of 12 letters then
 Display Password is Invalid Message
 elsif Password Does Have a Puncuation mark, One letter, one Number, a Capital letter, At Least 6 charecters And A max of 12 letters then
 Display Password Is Valid Message
 end if
 
 End for
/*
 


That's my code and I just need to know if that's how I make it ask for the password 5 times, using the for loop.
Sponsor
Sponsor
Sponsor
sponsor
syntax_error




PostPosted: Sun Dec 07, 2008 7:23 pm   Post subject: RE:Pseudocode problem

var count.
Insectoid




PostPosted: Sun Dec 07, 2008 7:23 pm   Post subject: RE:Pseudocode problem

You don't need to check the ascii values, you can do
code:

if pass[1] > A and pass[1]<Z then
    pass [1] valid
end if
NEOS




PostPosted: Sun Dec 07, 2008 8:06 pm   Post subject: Re: Pseudocode problem

but if I don't check the acsii code then how will the computer know what's greater than A and less than Z?
Tony




PostPosted: Sun Dec 07, 2008 8:34 pm   Post subject: RE:Pseudocode problem

because otherwise you are applying the same function to both sides of the equation
code:

pass[1] >= 'A'

is the same as
code:

ord(pass[1]) >= ord('A')


Though ultimately you are still checking if a character is in a certain numeric range, even if you don't explicitly specify the conversion.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Insectoid




PostPosted: Sun Dec 07, 2008 9:20 pm   Post subject: RE:Pseudocode problem

Yeah, it does the same thing. It just reads better and requires less typing.
DanielG




PostPosted: Sun Dec 07, 2008 9:49 pm   Post subject: RE:Pseudocode problem

Turing basically does the ascii conversion for you when comparing them.
andrew.




PostPosted: Mon Dec 08, 2008 4:25 pm   Post subject: RE:Pseudocode problem

It would be something like this:

Constant:
password - The real password (string)

Variables:
passattempt - The password the user enters (string)
counter - A counter to check how many times you entered in a password (integer)

Main loop:
Clear screen
Print "Enter the password"
Get passattempt
Check if passattempt equals the password
If it does, then exit the loop
If it doesn't then add one to counter and say how may login attempts you used (counter out of 5)
Check if counter equals 5
If it does, then quit (not exit, terminate the program)

After the loop:
Whatever you want
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: