0
for /l %i% in (1, 1, 8) do (
    set /p x=
    set /p y=
    @set  /a "z=%x%/%y%
    echo %z%
    pause
)

This is just an example of a problem I'm having the loop doesn't work properly. And I don't know why. I see the command prompt pop open just for a fraction of a second. It's not supposed to do that.

I want it to repeat without having to copy and paste it a bunch of times like this:

set /p x=
set /p y=
@set  /a "z=%x%/%y%
echo %z%
pause
set /p x=
set /p y=
@set  /a "z=%x%/%y%
echo %z%
pause
set /p x=
set /p y=
@set  /a "z=%x%/%y%
echo %z%
pause
set /p x=
set /p y=
@set  /a "z=%x%/%y%
echo %z%
pause

This is the only way I can get it to work.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Kodi4444
  • 15
  • 4
  • 2
    Additional notes: `set /A` does not require any surrounding `%` (or `!`) symbols, you may just write `set /A z=x/y` instead; and you have unbalanced quotes `"`... – aschipfl Sep 12 '18 at 16:22

1 Answers1

0

Based on your incorrect usage of the For /L loop, which should read %%i, not %i% and following the advice provided in the comments, your script should look like one of the following examples.

  1. Without delayed expansion:

    @Echo Off
    For /L %%A In (1,1,8) Do (
        Set /P "x=Dividend: "
        Set /P "y=Divisor: "
        Set /A z=x/y
        Call Echo Quotient as integer: %%z%%
        Pause
        Set /P "x=Dividend: "
        Set /P "y=Divisor: "
        Set /A z=x/y
        Call Echo Quotient as integer: %%z%%
        Pause
        Set /P "x=Dividend: "
        Set /P "y=Divisor: "
        Set /A z=x/y
        Call Echo Quotient as integer: %%z%%
        Pause
        Set /P "x=Dividend: "
        Set /P "y=Divisor: "
        Set /A z=x/y
        Call Echo Quotient as integer: %%z%%
        Pause
    )
    
  2. With Delayed Expansion:

    @Echo Off
    SetLocal EnableDelayedExpansion
    For /L %%A In (1,1,8) Do (
        Set /P "x=Dividend: "
        Set /P "y=Divisor: "
        Set /A z=x/y
        Echo Quotient as integer: !z!
        Pause
        Set /P "x=Dividend: "
        Set /P "y=Divisor: "
        Set /A z=x/y
        Echo Quotient as integer: !z!
        Pause
        Set /P "x=Dividend: "
        Set /P "y=Divisor: "
        Set /A z=x/y
        Echo Quotient as integer: !z!
        Pause
        Set /P "x=Dividend: "
        Set /P "y=Divisor: "
        Set /A z=x/y
        Echo Quotient as integer: !z!
        Pause
    )
    

Please read the usage information at the command prompt for your two main commands:

For /?

 

Set /?
Compo
  • 36,585
  • 5
  • 27
  • 39