# Board index » delphi » Help translate Basic codeto Turbo Pascal

## Help translate Basic codeto Turbo Pascal

Just for fun could someone translate this Basic code
into Turbo Pascal.

LOCATE 5, 5
PRINT "Press a key: "
N = 1
DO
LOCATE 20, 20
PRINT N
N = N + 1
LOCATE 5, 18
a\$ = INKEY\$
LOOP WHILE LEN(a\$) = 0
PRINT a\$
LOCATE 6, 5

Thanks.

While we are at it how wolu you write the follwing
C code in Turbo Pascal

#include <conio.h>
#include <stdio.h>
main()
{
float salary;
clrscr();
printf("Enter your desired monthly salary:");  /* note there is no \n
at the end */
printf(" \$_______\b\b\b\b\b\b\b"); /* this picks up at the end of above
*/
scanf("%f", &salary);
printf("\n\t\$%.2f a month is \$%.2f a year.", salary, salary * 12.0);
printf("\rGee!\n");

}

Thanks.

P. Mushubi

## Re:Help translate Basic codeto Turbo Pascal

##### Quote
>Just for fun could someone translate this Basic code
>into Turbo Pascal.

I'm bored, so why not!
##### Quote
>    LOCATE 5, 5
>    PRINT "Press a key: "
>    N = 1
>    DO
>       LOCATE 20, 20
>       PRINT N
>       N = N + 1
>       LOCATE 5, 18
>       a\$ = INKEY\$
>    LOOP WHILE LEN(a\$) = 0
>    PRINT a\$
>    LOCATE 6, 5

uses
crt;
var
n   :   integer;
begin
gotoxy(5, 5);
write('Press a key:');
n := 1;
repeat
gotoxy(20, 20);
write(n);
inc(n);
gotoxy(18, 5);
until keypressed;
gotoxy(5, 6);
end.

##### Quote
>While we are at it how wolu you write the follwing
>C code in Turbo Pascal

Humph!  I don't even program in C, but I can still do it...

##### Quote
>#include <conio.h>
>#include <stdio.h>
>main()
>{
>    float salary;
>    clrscr();
>    printf("Enter your desired monthly salary:");  /* note there is no \n
>at the end */
>    printf(" \$_______\b\b\b\b\b\b\b"); /* this picks up at the end of above
>*/
>    scanf("%f", &salary);
>    printf("\n\t\$%.2f a month is \$%.2f a year.", salary, salary * 12.0);
>    printf("\rGee!\n");
>}

uses
crt;
var
salary   :   real;
begin
clrscr;
writeln;
write('        \$', salary:1:2, ' a month is \$', salary*12:1:2,
' a year');
writeln(#13'Gee!');  {not much purpose in this...}
end.
--
Michael Langton <*langt...@manawatu.gen.nz>

## Re:Help translate Basic codeto Turbo Pascal

>Just for fun could someone
>translate this Basic code
>into Turbo Pascal.
>LOCATE 5, 5                Gotoxy(5,5);
>PRINT "Press a key: "      Writeln('Press a key: ');
>N = 1                      N := 1;
>DO                         while not keypressed do
>LOCATE 20, 20                begin
>PRINT N                        inc(n);
>N = N + 1                      gotoxy(20,20);
>LOCATE 5, 18                   write(n);
>a\$ = INKEY\$                  end;
>LOOP WHILE LEN(a\$) = 0     a:=readkey;
>PRINT a\$                   gotoxy(5,18);
>LOCATE 6, 5                writeln(a);
>Thanks.                    gotoxy(6,5)
>P. Mushubi
Pretty much straight forward conversion, though I prefer using while loops,
repeat/until will also work to preform the loop. WHILE loops work like
WHILE/WEND in basic, where DO/UNTIL works like REPEAT/UNTIL in pascal.
Example: While not keypressed do        repeat