i have to do a seven segemtn display for 2 numbers but at the moment it looks like this:- http://i28.tinypic.com/a176ep.jpg but i want the 1 and 3 to be next to each other but i cannot seen to do this here is my pascal:-

Program sevensegmentdigit;
Uses Wincrt;

Var
   x,y,n1,n2 : integer;

   Procedure One;
      begin
         writeln('   ');
         writeln('  |');
         writeln('  |');
      end;

     procedure Two;
      begin
         writeln(' _ ');
         writeln(' _|');
         writeln('|_ ');
      end;

     procedure Three;
      begin
         writeln(' _ ');
         writeln(' _|');
         writeln(' _|');
      end;

     procedure Four;
      begin
         writeln('   ');
         writeln('|_|');
         writeln('  |');
      end;

     procedure Five;
      begin
         writeln(' _ ');
         writeln('|_ ');
         writeln(' _|');
      end;

     procedure Six;
      begin
         writeln(' _ ');
         writeln('|_ ');
         writeln('|_|');
      end;

     procedure Seven;
      begin
         writeln(' _ ');
         writeln('  |');
         writeln('  |');
      end;

     procedure Eight;
      begin
         writeln(' _ ');
         writeln('|_|');
         writeln('|_|');
      end;

     procedure Nine;
      begin
         writeln(' _ ');
         writeln('|_|');
         writeln('  |');
      end;

     procedure Zero;
      begin
         writeln(' _ ');
         writeln('| |');
         writeln('|_|');
      end;

Begin

     write('Is Your Number 1 or 2 Digits?...');
     readln(y);

     if y = 1 then

      begin

       write('Enter Number...');
       readln(x);

       if x = 1 then
         begin
           One
         end;

       if x = 2 then
         begin
           Two
         end;
      
       if x = 3 then
         begin
           Three
         end;

       if x = 4 then
         begin
           Four
         end;
   
       if x = 5 then
         begin
           Five
         end;

       if x = 6 then
         begin
           Six
         end;

       if x = 7 then
         begin
           Seven
         end;

       if x = 8 then
         begin
           Eight
         end;

       if x = 9 then
         begin
           Nine
         end;

       if x = 0 then
         begin
           Zero
         end;

       end;

       if y = 2 then
       begin
       writeln('Enter First Number...');
       readln(n1);
       writeln('Enter Second Number...');
       readln(n2);

       if n1 = 1 then
        begin
         One;
        end;

       if n1 = 2 then
        begin
         Two;
        end;

       if n1 = 3 then
        begin
         Three;
        end;

       if n1 = 4 then
        begin
         Four;
        end;

       if n1 = 5 then
        begin
         Five;
        end;

       if n1 = 6 then
        begin
         Six;
        end;

       if n1 = 7 then
        begin
         Seven;
        end;

       if n1 = 8 then
        begin
         Eight;
        end;

       if n1 = 9 then
        begin
         Nine;
        end;

       if n1 = 0 then
        begin
         Zero;
        end;


       if n2 = 1 then
        begin
         One;
        end;

       if n2 = 2 then
        begin
         Two;
        end;

       if n2 = 3 then
        begin
         Three;
        end;

       if n2 = 4 then
        begin
         Four;
        end;

       if n2 = 5 then
        begin
         Five;
        end;

       if n2 = 6 then
        begin
         Six;
        end;

       if n2 = 7 then
        begin
         Seven;
        end;

       if n2 = 8 then
        begin
         Eight;
        end;

       if n2 = 9 then
        begin
         Nine;
        end;

       if n2 = 0 then
        begin
         Zero;
        end;

    end;

End.

can some help me do this plz thank you :D

How non-standard are you willing to go?

The standard way, you will have to re-write your program to take a whole number and create a string for each part of the number.

For example, if given the number '42', you would make the strings

1:  '      _ '
2:  ' |_|  _|'
3:  '   | |_ '

If your numbers are always three lines high, this is easy enough. Just adjust your functions to append the correct stuff to the end of the strings instead of using writeln.

Then, once you are done calling the zero, one, two, etc. functions, writeln each of the three strings to the screen.


BTW, use a case statement instead of a zillion ifs.

Hope this helps.

i dont really understand can you explain that a bit more please

You need to write three separate lines of text for each number, right? But all the numbers must be horizontally arranged? So, get yourself three string variables and set them to the empty string to begin with:

var s1, s2, s3: string;
begin
  s1 := '';
  s2 := '';
  s3 := '';

Now, each number routine (zero, one, two, etc.) can add itself to the end of the strings.

procedure zero;
  begin
  s1 := s1 +' _ ';
  s2 := s2 +'| |';
  s3 := s3 +'|_|'
  end;

When done, you can print the strings with writeln:

writeln( s1 );
  writeln( s2 );
  writeln( s3 );

Hope this helps.

this doesnt really seem to work as i cant get them to be next to each other

Member Avatar for Micheus

this doesnt really seem to work as i cant get them to be next to each other

You must test the code that Duoas post for You. I think You don't.

Just try Duoas's code by other way - may be You can see:

var s1, s2, s3: string;

procedure zero;
  begin
  s1 := s1 +' _ ';
  s2 := s2 +'| |';
  s3 := s3 +'|_|';
  end;

procedure PrintResult;
begin
  writeln( s1 );
  writeln( s2 );
  writeln( s3 );
end;

begin
  s1 := '';
  s2 := '';
  s3 := '';
  
  zero; // 1st digit
  zero; // 2nd digit

  PrintResult;
end.

You will see this:

_  _
| || |
|_||_|

but i wnt the user to type in say 24 and 24 comes up

Member Avatar for Micheus

but i wnt the user to type in say 24 and 24 comes up

And You have had implement this at first. You just will need to use the code that You post at first in this thread and change it by using the Douas approach.

Your code was working. Isn't it right?
So, You just need to surronud display "problem" - It is that the Duoas had suggested to You. I just examplefy with Zero's procededure, You will need to change Your others number's procedures to use some thing like this: s1 := s1 +' |' ; and not some thing like this: writeln(' |');

bye

thanks for the advice i got this woroking, ive been working on this for over a week lol after 5 days i asked for help, thanks guys :D

thanks for the advice i got this woroking, ive been working on this for over a week lol after 5 days i asked for help, thanks guys :D

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.