Turbo Pascal
Started by
SOORENA
, Feb 08 2006 06:39 PM
#1
Posted 08 February 2006 - 06:39 PM
#2
Posted 08 February 2006 - 06:47 PM
And now we have to do your homework?
#3
Posted 08 February 2006 - 06:54 PM
well some help would be nice.
Edited by SOORENA, 08 February 2006 - 06:55 PM.
#4
Posted 08 February 2006 - 07:35 PM
does it have to use graphical interface or textual
#5
Posted 08 February 2006 - 09:00 PM
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:)
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.
#6
Posted 08 February 2006 - 09:59 PM
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.
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.
#7
Posted 09 February 2006 - 08:19 AM
Take the 'Correct Password' announcement out from the loop and put it after the loop . If the user enters the password correctly for the second time, use Break command to exit the loop.
Did that make sense?
Did that make sense?
#8
Posted 09 February 2006 - 03:22 PM
Thank you but I already got it finished and working, by the way thank you Hai Mac the break command worked very well.
#9
Posted 10 February 2006 - 11:04 AM
Break is always handy . You are welcome.
Similar Topics
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users