Author Topic: Re: GUESS MY NUMBER GAME  (Read 1270 times)

0 Members and 1 Guest are viewing this topic.

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: GUESS MY NUMBER GAME
« Reply #15 on: September 12, 2019, 06:07:54 am »
qbasic version of "guess my number game" 1 line
Code: QB64: [Select]
  1. 1 IF Russia = 0 THEN Russia = 2222: RANDOMIZE TIMER: num = INT(RND * 100) + 1: GOTO 1 ELSE IF Russia <> 0 THEN INPUT n: IF n < num THEN PRINT "MORE": GOTO 1 ELSE IF n > num THEN PRINT "less": GOTO 1 ELSE IF n = num THEN PRINT "da": END ELSE GOTO 1 'DANILIN Russia 9-9-2019 guessnum.bas
1 IF Russia = 0 THEN Russia = 2222: RANDOMIZE TIMER: num = INT(RND * 100) + 1: GOTO 1 ELSE IF Russia <> 0 THEN INPUT n: IF n < num THEN PRINT "MORE": GOTO 1 ELSE IF n > num THEN PRINT "less": GOTO 1 ELSE IF n = num THEN PRINT "da": END ELSE GOTO 1 'DANILIN Russia 9-9-2019 guessnum.bas

qbasic version of "guess my number game" 1 line

c# version of "guess my number game" 1 line
Code: [Select]
using System; using System.Text;namespace GURU { class Program { static void Main(string[] args) { Random rand = new Random(); int Russia = 0; int n = 0; int num = 0; dav: if(Russia == 0) {Russia = 2222; num = rand.Next(100)+1; goto dav; }else if (Russia != 0) {Console.Write("? "); n = Convert.ToInt32(Console.ReadLine());} if (n < num) { Console.WriteLine("MORE"); goto dav;}else if (n > num) { Console.WriteLine("less"); goto dav;}else if (n == num) {Console.Write("da"); Console.ReadKey(); }else goto dav;}}}// DANILIN Russia 9-9-2019 guessnum.csusing System; using System.Text;namespace GURU { class Program { static void Main(string[] args) { Random rand = new Random(); int Russia = 0; int n = 0; int num = 0; dav: if(Russia == 0) {Russia = 2222; num = rand.Next(100)+1; goto dav; }else if (Russia != 0) {Console.Write("? "); n = Convert.ToInt32(Console.ReadLine());} if (n < num) { Console.WriteLine("MORE"); goto dav;}else if (n > num) { Console.WriteLine("less"); goto dav;}else if (n == num) {Console.Write("da"); Console.ReadKey(); }else goto dav;}}}// DANILIN Russia 9-9-2019 guessnum.cs

c# version of "guess my number game" 1 line

... applause ...

speak Russian: UGADAI CHISLO = guess number
 
flag%20152.gif
   
flag-ssha-animatsionnaya-kartinka-0035.gif
 
flag%20152.gif
 
flag-ssha-animatsionnaya-kartinka-0035.gif

« Last Edit: September 12, 2019, 10:28:42 am by DANILIN »
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: GUESS MY NUMBER GAME
« Reply #16 on: September 12, 2019, 09:59:10 am »
And a shorter 1 liner!
Code: QB64: [Select]
  1. 1 IF U = S THEN S = INT(RND * 98) + 1: GOTO 1 ELSE IF U <> S THEN INPUT "0<Guess<99="; U: IF U = S THEN PRINT "=": GOTO 1 ELSE IF U < S THEN PRINT "+": GOTO 1 ELSE PRINT "-": GOTO 1

(and 2 numbers less LOL)
« Last Edit: September 12, 2019, 10:03:20 am by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: GUESS MY NUMBER GAME
« Reply #17 on: September 12, 2019, 07:02:08 pm »
Hi Bplus
Hi Danilin

about : used in the code ...
I have had to use it for giving a second instruction to the block of IF THEN ELSE END IF  because writing it on one line the limit of Qbasic/QB is to bring one instruction for block of then or of else
so :GOTO 2 is in the inner of logic of IF THEN ELSE END IF and not to  include external (to the IF) instructions


I agree that write one line program is crazy!


Programming isn't difficult, only it's  consuming time and coffee