Björn Fahller
April 26, 2017
50

# BASIC C++

Humorous lightning talk at ACCU 2017 and Sweden CPP Stockholm showing how to write BASIC in C++

April 26, 2017

## Transcript

1. ACCU 2017
BASIC
BASIC
C++
C++
Björn Fahller

2. ACCU 2017

3. ACCU 2017

4. ACCU 2017
B A S I C !

5. ACCU 2017
10 PRINT “BASIC ROXXORS!!!”
20 GOTO 10

6. ACCU 2017
10 LET MAX=10
20 LET X = 0
30 GOTO 60
40 X = INT(RND(1)*(MAX-1) + 1)
50 RETURN
60 GOSUB 40
70 LET TIMES=0
80 LET GUESS=0
90 LET MAXGUESS = 5
100 PRINT "Guess a number between 1 and ", MAX
110 FOR TIMES = 1 TO MAXGUESS
120 INPUT GUESS
130 IF GUESS == X THEN GOTO 220
140 LET RELATIVE="big"
150 IF GUESS > X THEN GOTO 170
160 RELATIVE = "small"
170 PRINT "Too ", RELATIVE
180 NEXT
190 PRINT "Fail after ", MAXGUESS, " tries"
200 PRINT "The number is ", X
210 GOTO 230
220 PRINT "Only ", TIMES, " guesses. Well done!"
230 LET RETRY = "N"
240 INPUT "Want to try again (Y/N)?", RETRY
250 IF RETRY=="Y"||RETRY=="y" THEN GOTO 60

7. ACCU 2017
10 LET MAX=10
20 LET X = 0
30 GOTO 60
40 X = INT(RND(1)*(MAX-1) + 1)
50 RETURN
60 GOSUB 40
70 LET TIMES=0
80 LET GUESS=0
90 LET MAXGUESS = 5
100 PRINT "Guess a number between 1 and ", MAX
110 FOR TIMES = 1 TO MAXGUESS
120 INPUT GUESS
130 IF GUESS == X THEN GOTO 220
140 LET RELATIVE="big"
150 IF GUESS > X THEN GOTO 170
160 RELATIVE = "small"
170 PRINT "Too ", RELATIVE
180 NEXT
190 PRINT "Fail after ", MAXGUESS, " tries"
200 PRINT "The number is ", X
210 GOTO 230
220 PRINT "Only ", TIMES, " guesses. Well done!"
230 LET RETRY = "N"
240 INPUT "Want to try again (Y/N)?", RETRY
250 IF RETRY=="Y"||RETRY=="y" THEN GOTO 60

8. ACCU 2017
Function getting a random number
10 LET MAX=10
20 LET X = 0
30 GOTO 60
40 X = INT(RND(1)*(MAX-1) + 1)
50 RETURN
60 GOSUB 40
70 LET TIMES=0
80 LET GUESS=0
90 LET MAXGUESS = 5
100 PRINT "Guess a number between 1 and ", MAX
110 FOR TIMES = 1 TO MAXGUESS
120 INPUT GUESS
130 IF GUESS == X THEN GOTO 220
140 LET RELATIVE="big"
150 IF GUESS > X THEN GOTO 170
160 RELATIVE = "small"
170 PRINT "Too ", RELATIVE
180 NEXT
190 PRINT "Fail after ", MAXGUESS, " tries"
200 PRINT "The number is ", X
210 GOTO 230
220 PRINT "Only ", TIMES, " guesses. Well done!"
230 LET RETRY = "N"
240 INPUT "Want to try again (Y/N)?", RETRY
250 IF RETRY=="Y"||RETRY=="y" THEN GOTO 60

9. ACCU 2017
Function getting a random number
10 LET MAX=10
20 LET X = 0
30 GOTO 60
40 X = INT(RND(1)*(MAX-1) + 1)
50 RETURN
60 GOSUB 40
70 LET TIMES=0
80 LET GUESS=0
90 LET MAXGUESS = 5
100 PRINT "Guess a number between 1 and ", MAX
110 FOR TIMES = 1 TO MAXGUESS
120 INPUT GUESS
130 IF GUESS == X THEN GOTO 220
140 LET RELATIVE="big"
150 IF GUESS > X THEN GOTO 170
160 RELATIVE = "small"
170 PRINT "Too ", RELATIVE
180 NEXT
190 PRINT "Fail after ", MAXGUESS, " tries"
200 PRINT "The number is ", X
210 GOTO 230
220 PRINT "Only ", TIMES, " guesses. Well done!"
230 LET RETRY = "N"
240 INPUT "Want to try again (Y/N)?", RETRY
250 IF RETRY=="Y"||RETRY=="y" THEN GOTO 60

10. ACCU 2017
Function getting a random number
For loop
10 LET MAX=10
20 LET X = 0
30 GOTO 60
40 X = INT(RND(1)*(MAX-1) + 1)
50 RETURN
60 GOSUB 40
70 LET TIMES=0
80 LET GUESS=0
90 LET MAXGUESS = 5
100 PRINT "Guess a number between 1 and ", MAX
110 FOR TIMES = 1 TO MAXGUESS
120 INPUT GUESS
130 IF GUESS == X THEN GOTO 220
140 LET RELATIVE="big"
150 IF GUESS > X THEN GOTO 170
160 RELATIVE = "small"
170 PRINT "Too ", RELATIVE
180 NEXT
190 PRINT "Fail after ", MAXGUESS, " tries"
200 PRINT "The number is ", X
210 GOTO 230
220 PRINT "Only ", TIMES, " guesses. Well done!"
230 LET RETRY = "N"
240 INPUT "Want to try again (Y/N)?", RETRY
250 IF RETRY=="Y"||RETRY=="y" THEN GOTO 60

11. ACCU 2017
Function getting a random number
For loop
Output is trivial!
10 LET MAX=10
20 LET X = 0
30 GOTO 60
40 X = INT(RND(1)*(MAX-1) + 1)
50 RETURN
60 GOSUB 40
70 LET TIMES=0
80 LET GUESS=0
90 LET MAXGUESS = 5
100 PRINT "Guess a number between 1 and ", MAX
110 FOR TIMES = 1 TO MAXGUESS
120 INPUT GUESS
130 IF GUESS == X THEN GOTO 220
140 LET RELATIVE="big"
150 IF GUESS > X THEN GOTO 170
160 RELATIVE = "small"
170 PRINT "Too ", RELATIVE
180 NEXT
190 PRINT "Fail after ", MAXGUESS, " tries"
200 PRINT "The number is ", X
210 GOTO 230
220 PRINT "Only ", TIMES, " guesses. Well done!"
230 LET RETRY = "N"
240 INPUT "Want to try again (Y/N)?", RETRY
250 IF RETRY=="Y"||RETRY=="y" THEN GOTO 60

12. ACCU 2017
For loop
Output is trivial!
Function getting a random number
And so is input
10 LET MAX=10
20 LET X = 0
30 GOTO 60
40 X = INT(RND(1)*(MAX-1) + 1)
50 RETURN
60 GOSUB 40
70 LET TIMES=0
80 LET GUESS=0
90 LET MAXGUESS = 5
100 PRINT "Guess a number between 1 and ", MAX
110 FOR TIMES = 1 TO MAXGUESS
120 INPUT GUESS
130 IF GUESS == X THEN GOTO 220
140 LET RELATIVE="big"
150 IF GUESS > X THEN GOTO 170
160 RELATIVE = "small"
170 PRINT "Too ", RELATIVE
180 NEXT
190 PRINT "Fail after ", MAXGUESS, " tries"
200 PRINT "The number is ", X
210 GOTO 230
220 PRINT "Only ", TIMES, " guesses. Well done!"
230 LET RETRY = "N"
240 INPUT "Want to try again (Y/N)?", RETRY
250 IF RETRY=="Y"||RETRY=="y" THEN GOTO 60

13. ACCU 2017
For loop
Output is trivial!
Function getting a random number
And so is input
10 LET MAX=10
20 LET X = 0
30 GOTO 60
40 X = INT(RND(1)*(MAX-1) + 1)
50 RETURN
60 GOSUB 40
70 LET TIMES=0
80 LET GUESS=0
90 LET MAXGUESS = 5
100 PRINT "Guess a number between 1 and ", MAX
110 FOR TIMES = 1 TO MAXGUESS
120 INPUT GUESS
130 IF GUESS == X THEN GOTO 220
140 LET RELATIVE="big"
150 IF GUESS > X THEN GOTO 170
160 RELATIVE = "small"
170 PRINT "Too ", RELATIVE
180 NEXT
190 PRINT "Fail after ", MAXGUESS, " tries"
200 PRINT "The number is ", X
210 GOTO 230
220 PRINT "Only ", TIMES, " guesses. Well done!"
230 LET RETRY = "N"
240 INPUT "Want to try again (Y/N)?", RETRY
250 IF RETRY=="Y"||RETRY=="y" THEN GOTO 60
Highly visible control flow
without looking up names

14. ACCU 2017
For loop
Output is trivial!
And so is input
Function getting a random number
10 LET MAX=10
20 LET X = 0
30 GOTO 60
40 X = INT(RND(1)*(MAX-1) + 1)
50 RETURN
60 GOSUB 40
70 LET TIMES=0
80 LET GUESS=0
90 LET MAXGUESS = 5
100 PRINT "Guess a number between 1 and ", MAX
110 FOR TIMES = 1 TO MAXGUESS
120 INPUT GUESS
130 IF GUESS == X THEN GOTO 220
140 LET RELATIVE="big"
150 IF GUESS > X THEN GOTO 170
160 RELATIVE = "small"
170 PRINT "Too ", RELATIVE
180 NEXT
190 PRINT "Fail after ", MAXGUESS, " tries"
200 PRINT "The number is ", X
210 GOTO 230
220 PRINT "Only ", TIMES, " guesses. Well done!"
230 LET RETRY = "N"
240 INPUT "Want to try again (Y/N)?", RETRY
250 IF RETRY=="Y"||RETRY=="y" THEN GOTO 60
No tabs vs. spaces

15. ACCU 2017
For loop
Output is trivial!
Function getting a random number
And so is input
10 LET MAX=10
20 LET X = 0
30 GOTO 60
40 X = INT(RND(1)*(MAX-1) + 1)
50 RETURN
60 GOSUB 40
70 LET TIMES=0
80 LET GUESS=0
90 LET MAXGUESS = 5
100 PRINT "Guess a number between 1 and ", MAX
110 FOR TIMES = 1 TO MAXGUESS
120 INPUT GUESS
130 IF GUESS == X THEN GOTO 220
140 LET RELATIVE="big"
150 IF GUESS > X THEN GOTO 170
160 RELATIVE = "small"
170 PRINT "Too ", RELATIVE
180 NEXT
190 PRINT "Fail after ", MAXGUESS, " tries"
200 PRINT "The number is ", X
210 GOTO 230
220 PRINT "Only ", TIMES, " guesses. Well done!"
230 LET RETRY = "N"
240 INPUT "Want to try again (Y/N)?", RETRY
250 IF RETRY=="Y"||RETRY=="y" THEN GOTO 60
No tabs vs. spaces
No snake_case vs CamelCase

16. ACCU 2017
For loop
Output is trivial!
Function getting a random number
And so is input
10 LET MAX=10
20 LET X = 0
30 GOTO 60
40 X = INT(RND(1)*(MAX-1) + 1)
50 RETURN
60 GOSUB 40
70 LET TIMES=0
80 LET GUESS=0
90 LET MAXGUESS = 5
100 PRINT "Guess a number between 1 and ", MAX
110 FOR TIMES = 1 TO MAXGUESS
120 INPUT GUESS
130 IF GUESS == X THEN GOTO 220
140 LET RELATIVE="big"
150 IF GUESS > X THEN GOTO 170
160 RELATIVE = "small"
170 PRINT "Too ", RELATIVE
180 NEXT
190 PRINT "Fail after ", MAXGUESS, " tries"
200 PRINT "The number is ", X
210 GOTO 230
220 PRINT "Only ", TIMES, " guesses. Well done!"
230 LET RETRY = "N"
240 INPUT "Want to try again (Y/N)?", RETRY
250 IF RETRY=="Y"||RETRY=="y" THEN GOTO 60
No tabs vs. spaces
No snake_case vs CamelCase
No naming of functions or types

17. ACCU 2017
10 LET MAX=10
20 LET X = 0
30 GOTO 60
40 X = INT(RND(1)*(MAX-1) + 1)
50 RETURN
60 GOSUB 40
70 LET TIMES=0
80 LET GUESS=0
90 LET MAXGUESS = 5
100 PRINT "Guess a number between 1 and ", MAX
110 FOR TIMES = 1 TO MAXGUESS
120 INPUT GUESS
130 IF GUESS == X THEN GOTO 220
140 LET RELATIVE="big"
150 IF GUESS > X THEN GOTO 170
160 RELATIVE = "small"
170 PRINT "Too ", RELATIVE
180 NEXT
190 PRINT "Fail after ", MAXGUESS, " tries"
200 PRINT "The number is ", X
210 GOTO 230
220 PRINT "Only ", TIMES, " guesses. Well done!"
230 LET RETRY = "N"
240 INPUT "Want to try again (Y/N)?", RETRY
250 IF RETRY=="Y"||RETRY=="y" THEN GOTO 60

18. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

19. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

20. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

21. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

22. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

23. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

24. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

25. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

26. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

27. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

28. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

29. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

30. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

31. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

32. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

33. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

34. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}

35. ACCU 2017
#include
int main() {
_10: LET MAX=10;
_20: LET X = 0;
_30: GOTO _60;
_40: X = INT(RND(1)*(MAX-1) + 1);
_50: RETURN;
_60: GOSUB _40;
_70: LET TIMES=0;
_80: LET GUESS=0;
_90: LET MAXGUESS = 5;
_100:PRINT "Guess a number between 1 and ", MAX;
_110:FOR TIMES = 1 TO MAXGUESS;
_120:INPUT GUESS;
_130:IF GUESS == X THEN GOTO _220;
_140:LET RELATIVE="big";
_150:IF GUESS > X THEN GOTO _170;
_160:RELATIVE = "small";
_170:PRINT "Too ", RELATIVE;
_180:NEXT;
_190:PRINT "Fail after ", MAXGUESS, " tries";
_200:PRINT "The number is ", X;
_210:GOTO _230;
_220:PRINT "Only ", TIMES, " guesses. Well done!";
_230:LET RETRY = "N";
_240:INPUT "Want to try again (Y/N)?", RETRY;
_250:IF RETRY=="Y"||RETRY=="y" THEN GOTO _60;
}
C++ today is as
simple as BASIC
was in the 80s!

36. ACCU 2017

https://github.com/rollbear/basicpp
Björn Fahller
@bjorn_fahller
cpplang.slack.com
@rollbear
swedencpp.slack.com