0

I want a very simple batch file that allows me to add to number together i was thinking something like

@echo off
Set /a number1=enter a number
Set /a number2=enter your second number
set /a sum1==%number1%+%number2%
echo your fist numer was %number1% and your second number was %number2%
echo When you add them both together you get %sum1% hmmmmmmmmmmmmmm
pause

1
  • 3
    What is your question? Commented Oct 21, 2013 at 22:23

2 Answers 2

1

Use /p to prompt for input

@echo off
Set /p number1=Enter a number: 
Set /p number2=Enter your second number:
set /a sum1=%number1%+%number2%
echo your fist numer was %number1% and your second number was %number2%
echo When you add them both together you get %sum1% hmmmmmmmmmmmmmm
pause
Sign up to request clarification or add additional context in comments.

Comments

1
@echo off
Set /p numbera=Enter a number: 
Set /p numberb=Enter a second number: 
set /a sum=numbera+numberb
echo your fist numer was %numbera% and your second number was %numberb%
echo When you add them both together you get %sum% hmmmmmmmmmmmmmm
pause>nul

I think this method looks cleaner. use set /p for input, and use = not == for setting variables. here is an example.

set x=2
set y=3
set /a z=x+y+2
echo z is equal to %z%
pause>nul

the output should be z is equal to 7. as you can see, x+y+2 looks more like math than %x%+%y%+2.
if I missed something in my explanation, comment and I will fix it. please mark as correct answer if this helped so I can know that I answered the question.
; ) have fun!!

1 Comment

Can you edit to show an example of how to use the variable setting method mentioned?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.