Hey,
I am taking a windows scripting class and we are just getting started. I am new at this and having trouble creating the correct script for the home work assignment.
The requirements:
-Write a script to calculate the userÂ’s age in
months (age in years * 12)
-The script will expect the name (firstname
lastname) as parameter 1 and the age as
parameter 2
- If the user does not supply the parameters,
prompt for the values
-Use some type of input verification so the script can user cannot pass commands
Here is what I came up with:
@echo off
If {%1}=={} (set /p name="What is your name: " ELSE set name=%1)
If {%2}=={} (set /p age="What is your age: " ELSE set age=%2)
set /a age*=12
echo Name: %name%
echo Age in months: %age%
There are a couple of problems that I am encountering with my example. I dont know how to implement the verification for input. The program is working fine when the user does not pass any parameters through the command. Also their is another issue that is happening with the variables. It seems if you constantly use the command the variables keep the data stored from the previous time ran. I was just wondering if anyone knew what I was doing wrong or if this a good start to what I am trying to do.
Thanks,
integracd