Page 1 of 1

Calculator

Posted: 13 Nov 2013 22:14
by Scythe
Hello everyone, I decided to make a fun tool, a simple calculator.
NOTE: I only programmed ADDITION to work (For now)

Looks like this:

Calculator Test
Enter First Value (Enter any number here then press enter)
Enter Second Value (Enter any number here then press enter)
"first number" + "second number" = "the result"


Try not to enter extremely high numbers or it will probably crash (Also, do not use letters!)

A little confession: This was coded in c++ but was programmed to run in CMD (Runs exactly like a batch file) :)


Well If you guys like it, I can keep working on it :P Thanks, and good day to you all!

Re: Calculator

Posted: 13 Nov 2013 22:17
by Scythe

Re: Calculator

Posted: 14 Nov 2013 03:40
by dwngrt
Great man, you totally should keep on playing around with batch if you enjoy it much ^_^
you should add something like this to make it a bit more advanced and more useful for different sums ;)

Code: Select all

set i=
set /p i=[+ - / X]


so then you can do something like
%value% %i% %value2%

i dunno how calculating exactly work with batch but its defo possible :3

Re: Calculator

Posted: 14 Nov 2013 08:55
by Squashman
Judago wrote a couple of pure math batch files that can exceed the 32 bit integer limit of SET /A.

Re: Calculator

Posted: 14 Nov 2013 10:01
by Scythe
Yeah, I make remake one in Batch for fun :P But i'll probably add some more functionalities with my c++ version :D

Re: Calculator

Posted: 14 Nov 2013 11:03
by Squashman
Scythe wrote:Yeah, I make remake one in Batch for fun :P But i'll probably add some more functionalities with my c++ version :D

I appreciate your contribution but we do mainly just focus on batch files here.

Re: Calculator

Posted: 15 Nov 2013 01:22
by Batch Artist

Code: Select all

:CalculatorProgram
@echo off
color C
:root
cls
echo ====================================
echo =Welcome To CMD Calculator by PROXY=
echo ====================================
echo Press 1,2 or 3 for menus
echo 1.) Calculator
echo 2.) Instructions
echo 3.) Info
set /p !=
if %!% == 1 goto Calculator
if %!% == 2 goto Instructions
if %!% == 3 goto Info
:Calculator
cls
color D
echo ======================
echo Previous Answer= %ans%
echo ----------------------
set /p sum=
set /a ans=%sum%
echo = %ans%
goto Calculator
set /p !=
cls
echo ==================================
echo Previous Answer %ans%
goto top
pause
:Instructions
cls
color A
echo To use calculator-
echo Insert Number N
echo use the + key to add
pause
echo use the - key to subtract
pause
echo use the * key to multiply
pause
echo use the / key to divide
pause
echo Got It? (y,n)
set /p !=
if %!% == Y goto root
if %!% == y goto root
if %!% == N goto Instructions
if %!% == n goto Instructions
pause
:Info
cls
echo ====================================
echo =Welcome To CMD Calculator by PROXY=
echo ====================================
color B
echo This calculator was created by Batch Artist
pause
echo Would you like to return to the main menu? (y,n)
set /p m=
if %m% == Y goto root
if %m% == y goto root
if %m% == N goto Info
if %m% == n goto Info


This will also work and this has multiplication, division, subtraction and addition.

Re: Calculator

Posted: 15 Nov 2013 02:37
by foxidrive
I have a couple of comments, Batch Artist.

Using /i makes the compare case insensitive so you don't need multiple statements, and using double quotes protects against errors when no input is entered (and the variable is blank), as well as if two words were entered.

Code: Select all

if /i "%m%"=="y" goto :yes


The other thing is that the ! as a variable name is ok where you use it, but it is better to avoid using it because when you use delayed expansion, the ! will fail.

Re: Calculator

Posted: 15 Nov 2013 07:09
by Squashman
Batch Artist,
Your script will not work with numbers larger than 2,147,483,647.

Re: Calculator

Posted: 16 Nov 2013 04:32
by Batch Artist
Squashman wrote:Batch Artist,
Your script will not work with numbers larger than 2,147,483,647.

Ahhh, I gotta look into that. Thank you!

Re: Calculator

Posted: 16 Nov 2013 04:32
by Batch Artist
foxidrive wrote:I have a couple of comments, Batch Artist.

Using /i makes the compare case insensitive so you don't need multiple statements, and using double quotes protects against errors when no input is entered (and the variable is blank), as well as if two words were entered.

Code: Select all

if /i "%m%"=="y" goto :yes


The other thing is that the ! as a variable name is ok where you use it, but it is better to avoid using it because when you use delayed expansion, the ! will fail.


I will keep all that in mind. Thank you very much Foxidrive!

Re: Calculator

Posted: 23 Nov 2013 17:12
by Scythe
Sorry about that everyone, I just figured out how to make all calculator elements into one :P Well, i'm going back to batch and i'll post some more projects here.

Re: Calculator

Posted: 23 Nov 2013 18:04
by trebor68
In this forum was a thread and there also a link to a calculator:

thread: http://www.dostips.com/forum/viewtopic.php?f=3&t=4279

link: http://judago.webs.com/batchfiles.htm
See there: STR_MATH.BAT