Making a basic Calculator (+, -, x, /)

Juanita
06-02-2002, 03:20 PM
Hello,

I just located this site and signed up today. I'm new to VB (1 week), am in a condensed 5-week "Introduction" course.

(1) Assignment is to create a basic calculator (numbers 0-9) with four arithmetic functions (+, -, x, /).

(2) First step: I created the actual calculator form in VB (title, display box, number buttons 0-9, four arithmetic buttons, decimal point button, and equal button). Didn't think you needed to see that generic code.

(3) Second step: I created a flowchart. :confused: :confused: Would appreciate expert critiques to review it and determine if my initial logic is on track. (Assuming major tasks need to be separate functions/calls(?) exact methods TBD later, premature for me at this point)

Thank you so much for some initial direction / help / advice.

Tried sending the Visio file, didn't work (duh) ... obviously cannot insert flowchart image into a text file ... so saved image as a .jpg file. Hope it converted correctly.

~ Juanita

Bucky
06-02-2002, 03:27 PM
Do a forum search for "calculator" and you'll find lots of examples of calculator programs there.

Good luck.

Juanita
06-02-2002, 03:35 PM
Hi Bucky, thank you for the quick reply.

Yes, I have already done a search on 'calculator', read through quite a few postings, lotsa threads and pieces of information. Some of it beyond where I am at right now. For example, someone did theirs using an array, but that is beyond my capability at this point. Also seen skads of pieces of programming examples.

Was looking just for some initial basic logic or comments on how I am viewing this. Or even advice on what are some better methods ... keeping in mind there are "nine ways to skin a cat", just trying to get a grip with some good advice on how to go forward.

Thks again.

Thinker
06-02-2002, 06:43 PM
The basic flow chart is ok, but to put this into practice in code, you
will need to determine how to either: control the user so they can
only do the correct thing at any time or, have a lot of code that
can make assumptions about what the user wants to do. For
instance, you have the user clicking the = to get the result. You
would either have to disable all the other function buttons so they
couldn't click * again, or assume that clicking * meant do the
function on the first two values, then use the result as the first
value in a new multiply operation.

Juanita
06-02-2002, 07:01 PM
Thinker,

Thank you. That is the kind of insight I need, makes me rethink the logic on how to approach this. Appreciate your guidance. All this is new for me, but it helped pick my brain, I see what you are saying.

~ Juanita

loquin
06-02-2002, 08:29 PM
I'm thinking you will want to have user enter first number.

Then user enters +, -, *, or /. This triggers storing first value in a result buffer. You also need to store operation in a buffer.

Then users enters second number. Then presses = . Now you all three pieces of info you need. The stored first value, the stored operation. And the second value in the textbox.

Perform your calculation, clear the display, and write the result.



But, with a standard calculator, you COULD enter 7, +, 3, + (here the calculator displays 10) , 4, = (and the calculator displays 14)

If the user enters an operator other than = in the example above, you will need to perform the calculation and display the result LIKE the = had been pressed, but also save the result (and the new operation) in the buffer and operation buffer as well.



I would suggest to get the program working for one calculation at a time, then expand it to work on 'running' calculations.

Juanita
06-02-2002, 09:26 PM
loquin,

Yah that helps! Perfect, thank you! You identified add'l key issues I needed. I definitely got the jest of the overall concept. I'm set now and can go forward with this.

~ Juanita

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum