-2

So I recently started learning making .bat file and I'm asked to make a guessing game. my variable is some why being set with a space after the name, any ideas?

@echo off
set /A number=%random%

echo type your guess

set /P /a guess=
set guess
Magoo
  • 77,302
  • 8
  • 62
  • 84
  • 1
    The option `/A` is for interpreting the argument string(s) following as __arithmetic expression__ and the option `/P` is for __prompting__ a user for a string assigned to an environment variable if the user inputs a non-empty string at all. It is not possible to use these two options together. Open a [command prompt](https://www.howtogeek.com/235101/), run `set /?` and read the output help carefully and completely. See also: [Why is no string output with 'echo %var%' after using 'set var = text' on command line?](https://stackoverflow.com/a/26388460/3074564) It contains additional information. – Mofi Jan 11 '21 at 09:06
  • The second line after `@echo off` should be already `set "number=%random%"` (recommended syntax) or just `set number=%random%`. There is nearly never the need to use an arithmetic expression to assign a (random) number to an environment variable. – Mofi Jan 11 '21 at 09:09

1 Answers1

1

You cannot use /a and /p together. Batch sets a variable called /a guess to the value received.

Magoo
  • 77,302
  • 8
  • 62
  • 84