Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Turbo Pascal


  • Please log in to reply

#1
SOORENA

SOORENA

    Member

  • Member
  • PipPipPip
  • 974 posts
I have to do this assignment for class and my teacher wants a program that uses a while loop to ask the user to give a 2 character password, if the password is right then its gives a welcoming message, if not they have three chances to guess and if all of them are wrong then a nasty message is given and program is exited. You can use constants, if statements, else statements, bolean expressions, variables, and clear screen, (what i've learned so far).
  • 0

Advertisements


#2
memberix

memberix

    Member

  • Member
  • PipPipPip
  • 160 posts
And now we have to do your homework?
  • 0

#3
SOORENA

SOORENA

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 974 posts
well some help would be nice. :tazz:

Edited by SOORENA, 08 February 2006 - 06:55 PM.

  • 0

#4
memberix

memberix

    Member

  • Member
  • PipPipPip
  • 160 posts
does it have to use graphical interface or textual
  • 0

#5
jackmanplus

jackmanplus

    New Member

  • Member
  • Pip
  • 4 posts
i'm learning C++, but if its similair you should be able to:
create a for loop, loop counter i, set equal to 1. condition set to i<=3. increment add one to i.

then make a promt for their password and store as pass.
then make an if statement and test to see if the password they gave is equal to the correct password.
if the password is correct, the statements under if will execute, so put a break, to exit from the for loop.
if the password is incorrect, the statements will not execute, so put a message like password is incorrect, try agian, and the for loop will add one to i and execute agian.(thus giving them three chances)


ok, the only way i see to give them a nasty message after three incorrect would be to put another if statement in right after your first if statement. In this if statement test for i equal to 3, and if it is equal , then you could display your "nasty" message and you could return control to the operating system, not sure how to do this in Turbo Pascal but in C++ its
return(0);

hope that helps:)

Edited by jackmanplus, 08 February 2006 - 09:02 PM.

  • 0

#6
SOORENA

SOORENA

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 974 posts
Sorry but non of that is making sense to me but here is what i've managed to get so far:

Program PasswordRejection (input, output);

uses crt;

var
name:string;
password:integer;
counter:integer;
Y:char;
begin

password:=14;
counter:=0;

clrscr;


writeln('PASSWORD GUESSING':48);
writeln;

writeln('THIS PROGRAM IS TO ASK YOU FOR THE CORRECT PASSWORD.');
writeln;

writeln('Please enter your name');
readln(name);

writeln('Please enter Password as a whole number:');
readln(password);

if password=14 then

begin
writeln('Welcome ', name);
end

else
while counter<>2 do


begin
counter:=counter+1;

writeln('Please Enter Correct Password');

readln(password);
if password=14 then
begin




writeln('Welcome ', name);
end;



end;



if password<>14 then

begin
writeln('Sorry, ',name,' but wrong password');
writeln;
end;
writeln('Please type Y to exit');
readln(y);
end.

now the problem is that after the password is correct the second time it says that the password is right but also says to enter the correct password again.

Edited by SOORENA, 08 February 2006 - 10:00 PM.

  • 0

#7
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Take the 'Correct Password' announcement out from the loop and put it after the loop :tazz:. If the user enters the password correctly for the second time, use Break command to exit the loop.

Did that make sense? :)
  • 0

#8
SOORENA

SOORENA

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 974 posts
Thank you but I already got it finished and working, by the way thank you Hai Mac the break command worked very well.
  • 0

#9
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Break is always handy :tazz:. You are welcome.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP