Title: Request for Calculator tutorial Post by: GarrisonRicketson on March 11, 2011, 03:59:54 pm I was just looking at some old programs, and old posts,..and remembered,
I had been trying to make a calculator,...but never really did, ...I would like to see a tutorial on this, for qb64,..in the qb64 tutoriials, or here... Where ever is most appropriate... from Garry Title: Re: Request for Calculator tutorial Post by: GarrisonRicketson on March 11, 2011, 08:06:42 pm Ok, yea a simple one,..just add,multiply, divide Twice now, the Calculator, that comes with windows, got deleted, as a virus, by my anti virus soft ware!,..but I don't need one that fancy...
Sorry I did not know that is one of your weak points, well I guess I do remember, you mentioned, math was a weak area, me too, that is why I need a calculator. Thanks.... Title: Re: Request for Calculator tutorial Post by: guest on March 11, 2011, 08:48:02 pm Hi all,
Here's the start of a Calculator Program with the theory first. Quote TO MAKE A CALCULATOR Part I Ok how do we make a calcuklator? Well we start with the basic functions that are needed. 1] Add 2] Subtract 3] Multiply 4] Divide To make these functions we will need some data. We will obviously need the numbers 0123456789 and the symbols Add (+), Subtract (-), Multiply (*), Divide (\), Equals (=),clear entry (c), clear all (a), Dot (.). So we will need to crate them as objects. These will be objects that we click on with the mouse and by clicking on them we use them. These objects need to be selected in the right sequence else we will create an error. As humans if we selected the add symbol first and two numbers after we understand what it is we wish to do. The computer can not do this. It needs defined and predictable actions to respond to. So this means we have to have a set of rules that the program understands and follows to arrive at the correct answer. Before we come to the constructed actions of using these objects we need to define the data types that will be used. An integer can be only minus 32,768 to 32,767. This size may not be big enough for some operations. Also if a user enters a floating point figure (eg. 99.33) that will not work in an integer. We basically need two types LONG INTEGER(&) and SINGLE(!).Somehow we need to detect if a user enters a DOT and make the appropriate type selection based on that. One way to allow any entry is to use strings$. We would build the string of numbers entered until the user selects a symbol. Before we react to the symbol we scan the string$ for the dot. If we detect the dot then we have to use the FLOAT type. Next we would decode the string into our first variable. So recapping the string gets converted into a FLOAT or a SINGLE. The only other thing that need to be monitored is if the entered number is positive or negative. This could potentially complicate it for us. The most obvious thing that i can think of to differenciate between the symbol minus and negative is to use minus as an action and then negative and positive as a condition. So in theory now we have to add 2 new symbols to indicate positive and negative that only affects the sign of numbers. Next is how the actions occur and get interpreted in the correct sequence. Normally a user enters a number. This number is assumed to be positive unless he indicates its negative with a different symbol selection. Next an operator is selected like addition. Next the user enters a second number that may be positive or negative. Lastly the user selects a result like equals. Action1 + Action2 + Action3 + Action4 results in a calculation that appears in an output variable. Title: Re: Request for Calculator tutorial Post by: SMcNeill on August 26, 2012, 05:26:35 pm A very simple calculator program for you:
Code: 'Very Basic Calculator Feel free to change, modify, expand, and use as needed. I tried to keep it simple so no one would have a problem understanding how it works, so all it does at the moment is add, subtract, multiply, and divide -- in sequential order. 12 + 1 * 3 = 39 Think of it along the lines of one of those 99 cent calculators you'd buy from the Dollar General store. ;) Title: Re: Request for Calculator tutorial Post by: GarrisonRicketson on August 26, 2012, 05:56:26 pm Thanks for posting this, it worked good. I compiled it with qb64 for Linux, from Garry |