Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Need help creating a script
Closed Thread
Old 09-11-2006, 03:58 PM   #1 (permalink)
 
Newb Techie

Join Date: Sep 2006

Posts: 1

integracd

Default Need help creating a script

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
integracd is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On