0

hi
program to ask the user a username and a password
if pass and username good display OK
else
clear screen and reask the user for username and password again.
this will continue until good username and password entred.
using while loops
thanks in advanced

3
Contributors
8
Replies
9
Views
9 Years
Discussion Span
Last Post by Duoas
0

i have got one of these working, but i am just gna hand it out, try it first for yourself then i will HELP you not just tell u the answers

0

here is the codes, its my first time am using pascal.

program security;
uses wincrt;

var
   username:string;
   password:string;
   counter:integer;
Begin
     counter:=1
     write('Username');
     readln(username);
     write('password');
     readln(password);

     if (username='admin') and (password='admin') then
        writeln('OK')

     else
         while (counter<= {how to define an error this is my prob} ) do


end.

here is what i'll tries, my prob is how to define an error dont no if u understant, but thanks for reply.

i made a program to calculate x to the power of y, so user input x and y, program calculate x to the power of y.
But problem is 6 to the power of 6 dont work, but 5 to power 5 works perfectly

here is the codes:

Program power;
uses wincrt;

var
   x:integer;
   y:integer;
   counter:integer;
   result:integer;
Begin
    write('Enter X=');
    readln(x);
    write('Enter y=');
    readln(y);
    counter:=1;
    result:=1;
    if y=0 then
       result:=0
    else
        while (counter<=y)do
              Begin
                    result:=(x*result);
                    counter:=counter+1;
              end;
    writeln('result=',result);

end.

Edited by mike_2000_17: Fixed formatting

0

You used the wrong bb code. When inserting code in your post place
[code]
before it and
[/code]
after it. Then it will look pretty and preserve whitespace.

Your power program works perfectly for me.

For the other, you need a somewhat tricky loop. Here's a help:

for num_tries := 3 downto 1 do 
  begin
  write( 'Username: ' );
  readln( username );

  write( 'Password: ' );
  readln( password );

  if (username = 'admin') and (password = 'admin')
    then break
    else begin
         writeln( 'You have ', num_tries -1, ' tries left.' )
         end
  end;

if (username <> 'admin') or (password <> 'admin') then
  begin
  writeln( 'Access denied!' );
  exit
  end;

writeln( 'Access granted!' );
...

You don't have to limit the number of tries. You could just loop until the username and password match. However you need it.

Hope this helps.

Edited by diafol: fixed formatting

0

Thanks for ur help.
i used it with repeat until:

program security;
uses wincrt;

var
   username:string;
   password:string;

Begin

     write('Username ');
     readln(username);
     write('password ');
     readln(password);

     if (username='admin') and (password='admin') then
        writeln('Access Granted')

     else
         while (username<>'admin') and (password<>'admin') do
              Begin
                   repeat
                        clrscr;
                        write('Username ');
                        readln(username);
                        write('password ');
                        readln(password);
                   until
                        (username='admin')and(password='admin');
                        writeln('Access Granted');
              end;      
end.

if i need any help that sure i'll come here LOL.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.