Calculator

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Scythe
Posts: 6
Joined: 13 Nov 2013 22:08

Calculator

#1 Post by Scythe » 13 Nov 2013 22:14

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!

Scythe
Posts: 6
Joined: 13 Nov 2013 22:08

Re: Calculator

#2 Post by Scythe » 13 Nov 2013 22:17


dwngrt
Posts: 26
Joined: 07 Oct 2013 05:14
Location: The Netherlands

Re: Calculator

#3 Post by dwngrt » 14 Nov 2013 03:40

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

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Calculator

#4 Post by Squashman » 14 Nov 2013 08:55

Judago wrote a couple of pure math batch files that can exceed the 32 bit integer limit of SET /A.

Scythe
Posts: 6
Joined: 13 Nov 2013 22:08

Re: Calculator

#5 Post by Scythe » 14 Nov 2013 10:01

Yeah, I make remake one in Batch for fun :P But i'll probably add some more functionalities with my c++ version :D

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Calculator

#6 Post by Squashman » 14 Nov 2013 11:03

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.

Batch Artist
Posts: 22
Joined: 18 Oct 2013 05:28

Re: Calculator

#7 Post by Batch Artist » 15 Nov 2013 01:22

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Calculator

#8 Post by foxidrive » 15 Nov 2013 02:37

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.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Calculator

#9 Post by Squashman » 15 Nov 2013 07:09

Batch Artist,
Your script will not work with numbers larger than 2,147,483,647.

Batch Artist
Posts: 22
Joined: 18 Oct 2013 05:28

Re: Calculator

#10 Post by Batch Artist » 16 Nov 2013 04:32

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!

Batch Artist
Posts: 22
Joined: 18 Oct 2013 05:28

Re: Calculator

#11 Post by Batch Artist » 16 Nov 2013 04:32

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!

Scythe
Posts: 6
Joined: 13 Nov 2013 22:08

Re: Calculator

#12 Post by Scythe » 23 Nov 2013 17:12

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.

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: Calculator

#13 Post by trebor68 » 23 Nov 2013 18:04

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

Post Reply