BATCH FILES...PLEASE HELP

Joined
Jan 28, 2023
Messages
5
Reaction score
0
exercise 1:
@echo off

setlocal enabledelayedexpansion

rem create list

set a[0]=michael

set a[1]=pique

set a[2]=elias
set a[3]=george

set a[4]=tobias



rem based on the table above and using

rem command for create the following content display:

michael tobias

pique george

elias elias

george pique

tobias michael



exercise 2:

make the (for) command work properly with the (reverse) command

@echo off

setlocal enabledelayedexpansion

rem create list

set a[0]=1

set a[1]=2

set a[2]=3

set a[3]=4

set a[4]=5



for /L %%x in (0,1,4) do (



set /a "reverse=4-%%x"

echo !a[%%reverse]!

rem echo !reverse!

)



pause
 
Joined
Jan 30, 2023
Messages
107
Reaction score
13
Here is the corrected version of both exercises:

Exercise 1:

Code:
@echo off
setlocal enabledelayedexpansion

rem create list
set a[0]=michael
set a[1]=pique
set a[2]=elias
set a[3]=george
set a[4]=tobias

rem based on the table above and using (for) command to create the following content display:
for /L %%x in (0,1,4) do (
    set /a "y=%%x+1"
    if !y! gtr 4 (set y=0)
    echo !a[%%x]! !a[!y!]!
)
pause

Exercise 2:

Code:
@echo off
setlocal enabledelayedexpansion

rem create list
set a[0]=1
set a[1]=2
set a[2]=3
set a[3]=4
set a[4]=5

rem using the (for) command with the (reverse) option to display the elements in reverse order
for /L %%x in (4,-1,0) do (
    echo !a[%%x]!
)
pause
 
Joined
Jan 28, 2023
Messages
5
Reaction score
0
First of all....REALLY THANK YOU for the reply,
the second exercise is perfect !
the first one shows me that:
michael y
pique y
elias y
george y
tobias y
Press any key to continue...
Question: How i can do this ? :
michael tobias

pique george

elias elias

george pique

tobias michael ?
BTW THANKS AGAIN FOR THE REPLY
 
Joined
Jan 30, 2023
Messages
107
Reaction score
13
First of all....REALLY THANK YOU for the reply,
the second exercise is perfect !
the first one shows me that:
michael y
pique y
elias y
george y
tobias y
Press any key to continue...
Question: How i can do this ? :
michael tobias

pique george

elias elias

george pique

tobias michael ?
BTW THANKS AGAIN FOR THE REPLY
Code:
@echo off
setlocal enabledelayedexpansion

rem create list
set a[0]=michael
set a[1]=pique
set a[2]=elias
set a[3]=george
set a[4]=tobias

rem based on the table above and using (for) command to create the following content display:
for /L %%x in (0,1,4) do (
    set /a "y=%%x+1"
    if !y! gtr 4 (set y=0)
    echo !a[%%x]! y
)
pause
 
Joined
Jan 28, 2023
Messages
5
Reaction score
0
Sorry to bother...now it only shows me this, i try it but i can't find a solution
set a[0]=michael
set a[1]=pique
set a[2]=elias
set a[3]=george
set a[4]=tobias
 
Joined
Jan 30, 2023
Messages
107
Reaction score
13
Sorry to bother...now it only shows me this, i try it but i can't find a solution
set a[0]=michael
set a[1]=pique
set a[2]=elias
set a[3]=george
set a[4]=tobias
You can achieve the desired output by modifying the code as follows:

@echo off setlocal enabledelayedexpansion

rem create list set a[0]=michael set a[1]=pique set a[2]=elias set a[3]=george set a[4]=tobias

rem based on the table above and using (for) command to create the following content display: for /L %%x in (0,1,4) do ( set /a "y=(%%x+2) % 5" echo !a[%%x]! !a[!y!]! ) pause

This code calculates the next index (y = (x + 2) % 5) in each iteration, which will result in the desired output. The final output will be:

michael tobias

pique george

elias elias

george pique

tobias michael
 
Joined
Jan 28, 2023
Messages
5
Reaction score
0
Please because probably im doing something wrong ....can you send me dm on (e-mail address removed) ? pls
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

POWERSHELL-BATCHFILE EXERCISE 2
Arduino Code Please Help 0
Code help please 4
Can't solve problems! please Help 0
HELP PLEASE 4
Help please 8
I dont get this. Please help me!! 2
Search Results with Pagination 1

Staff online

Members online

Forum statistics

Threads
474,056
Messages
2,570,439
Members
47,101
Latest member
DoloresHol

Latest Threads

Top