user2904788
user2904788

Reputation: 1

Adding 2 simple number together in a batch file

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

Upvotes: 0

Views: 149

Answers (2)

cure
cure

Reputation: 2688

@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!!

Upvotes: 1

JohnLBevan
JohnLBevan

Reputation: 24440

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

Upvotes: 1

Related Questions