hello!
i've got a code from QBasic which i need translating to C++
i've tried a somewhat code by code translation as to what i understand in C++
here is my Qbasic program
here's my translation in C++ (Dev C++)
so someone said i should change CLS to clrscr
debugging the program tells me to
-convert int to double
-undeclared clrscr
-some identifiers
-undeclared GOSUB, inkey$, CHR$, END
should i change PRINT to cout?
i've got a code from QBasic which i need translating to C++
i've tried a somewhat code by code translation as to what i understand in C++
here is my Qbasic program
sq = 50 t1 = .1 ’ tfac = .95 tend = .0001 maxmc = 6 RANDOMIZE TIMER CLS DIM x(sq), y(sq) FOR i = 0 TO sq - 1 x(i) = RND y(i) = RND NEXT i CLS GOSUB 1000 GOSUB 4000 l2 = lt DO GOSUB 5000 IF INKEY$ = CHR$(27) THEN END CLS GOSUB 1000 PRINT ”"Temperature"”; PRINT USING ''’’##.####’’''; t1 PRINT ''’’Energie’’''; PRINT USING ''’’###.#####''’’; l2 t1 = t1 * tfac LOOP UNTIL t1 <= tend END ’ 1000 SCREEN 2 LINE (100, 30)-(420, 160), , B FOR l = 0 TO sq - 1 CIRCLE (260 + 160 * x(l), 95 + 65 * y(l)), 3 NEXT l RETURN 4000 lt = 0 FOR i = 0 TO sq - 1 FOR k = 0 TO i - 1 u = 0 r2 = (((x(i) - x(k)) ^2 + (y(i) - y(k)) ^2)) IF r2 < .01 THEN 4020 ELSE GOTO 4010 4010 IF r2 < .03 THEN 4030 ELSE GOTO 4100 4020 u = 20 GOTO 4100 4030 u = -.001 / r2 GOTO 4100 4100 lt = lt + u NEXT k NEXT i RETURN ’'Monte Carlo 5000 FOR ntrial = 1 TO maxmc FOR h = 0 TO sq - 1 a = x(h) B = y(h) x(h) = 2 * RND - 1 y(h) = 2 * RND - 1 GOSUB 4000 IF lt <= l2 OR RND < EXP(-(lt - l2) / t1) THEN l2 = lt ELSE x(h) = a y(h) = B END IF NEXT h NEXT ntrial RETURN
here's my translation in C++ (Dev C++)
#include "QBasic.h"
#include <iostream>
#include <ctime>
using namespace std;
int main() {
int sq = 50 ;
int t1 = .01 ;
int tfac = .95 ;
int tend = .0001 ;
int maxmc = 6 ;
srand(static_cast<unsigned>(time(0))) ;
clrscr() ;
int x [ sq +1] , y [ sq +1] ;
//Start
for( int i = 0 ;i<=sq;i+=1){ - 1
x [ i ] = rand() ;
y [ i ] = rand() ;
} i
//main program
clrscr() ;
GOSUB 1000 ;
GOSUB 4000 ;
int l2 = lt ;
do {
GOSUB 5000 ;
if( inkey$() == CHR$ ( 27 ) ){ END
clrscr() ;
GOSUB 1000 ;
PRINT "TEMPERATURE" ; ;
PRINT USING " ##.#### " ; t1 ;
PRINT ; //'ENERGY'';
PRINT USING " ###.##### " ; 12 ;
t1 = t1 * tfac ;
} UNTIL t1 < = tend
END ;
//plotting
1000 //SCREEN 2
LINE ( 100 , 30 ) - ( 420 , 160 ) , , int B ;
for( int l = 0 ;l<=sq;l+=1){ - 1
CIRCLE ( 260 + 160 * x [ l ] , 95 + 65 * y [ l ] ) , 3 ;
} l
RETURN ;
//ENERGY
4000 lt = 0 ;
for( i = 0 ;i<=sq;i+=1){ - 1
for( int k = 0 ;k<=i;k+=1){ - 1
int u = 0 ;
int r2 = ( ( ( x [ i ] - x [ k ] ) ^ 2 + ( y [ i ] - y [ k ] ) ^ 2 ) ) ;
if( r2 < . int 01 ){ 4020 ELSE GOTO 4010 ;}
4010 if( r2 < . int 03 ){ 4030 ELSE GOTO 4010 ;}
4020 u = 20 ;
GOTO 4100 ;
4030 u = - . int 001 / r2 ;
GOTO 4100 ;
4100 lt = lt + u ;
} k
} i
RETURN ;
//MONTE CARLO
5000 for( int ntrial = ;ntrial<=maxmc;ntrial+=1){ maxmc
for( int h = 0 ;h<=sq;h+=1){ - 1
int a = x [ h ] ;
B = y [ h ] ;
x [ h ] = 2 * rand() - 1 ;
y [ h ] = 2 * rand() - 1 ;
GOSUB 4000 ;
if( lt < == 12 || rand() < EXP ( - ( lt - 12 ) / t1 ) ){
l2 = lt ;
ELSE x [ h ] = a ;
y [ h ] = B ;
}
} h
} ntrial
RETURN ;
return 0;
}
so someone said i should change CLS to clrscr
debugging the program tells me to
-convert int to double
-undeclared clrscr
-some identifiers
-undeclared GOSUB, inkey$, CHR$, END
should i change PRINT to cout?