| | |
Help With Some Pascal???
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2008
Posts: 26
Reputation:
Solved Threads: 0
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:-
can some help me do this plz thank you
Pascal and Delphi Syntax (Toggle Plain Text)
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
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
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.
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
Pascal and Delphi Syntax (Toggle Plain Text)
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.
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:
Now, each number routine (zero, one, two, etc.) can add itself to the end of the strings.
When done, you can print the strings with writeln:
Hope this helps.
Pascal Syntax (Toggle Plain Text)
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.
Pascal Syntax (Toggle Plain Text)
procedure zero; begin s1 := s1 +' _ '; s2 := s2 +'| |'; s3 := s3 +'|_|' end;
When done, you can print the strings with writeln:
Pascal Syntax (Toggle Plain Text)
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
Just try Duoas's code by other way - may be You can see:
Pascal Syntax (Toggle Plain Text)
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.
Pascal and Delphi Syntax (Toggle Plain Text)
_ _ | || | |_||_|
"It always has, at least, two ways to make one same thing. Exactly that they are certain and wrong"(Micheus)
Brazil - Blumenau
Brazil - Blumenau
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
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
"It always has, at least, two ways to make one same thing. Exactly that they are certain and wrong"(Micheus)
Brazil - Blumenau
Brazil - Blumenau
![]() |
Similar Threads
- Help With Pascal's Triangle in C++ (C++)
- Pascal starter. (Pascal and Delphi)
- Pseudo-Pascal Question: Need Help!! (Pascal and Delphi)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Some Basic Pascal Help Please :D
- Next Thread: help me..
| Thread Tools | Search this Thread |






