DEV Community

Discussion on: need help with c++ calculator

Collapse
 
lsponzoni profile image
Leon

Complementing Jason, you start here:
"The user must be able to add, subtract, multiply and divide as many times as he/she/it wants then get the result of be able to clear and start over."

Verbs are hints to subtasks: add, sub, mul, div, clear, get the result.
(Nouns are hints to variables and later on objects).: result

You thought a nice loop.
User goes: number, op, number, op, number,..., clear or result.

Or maybe: number, op, number, number, op, number,..., clear or result.
Should you reuse the result as operand for the next op?
Should the user be able to ask for "a sub formula"?
How do you track if user wants to use result as operand?
For example i_1 + i_2 - (i_3 + i_4)
Can the user go: "i_1 + clear" instead? What happens then?

A nice way to think and reason is a flow chart
Make a square for each action or calculation, put a arrow without anything when one thing leads to another.
Write an arrow for each different outcome of the box.
For example:
commons.wikimedia.org/wiki/File:Wr...

Hint: For now, you can ask for a number input and give options 1,2,... to interact with the user. Later, you can use c++ string, char and regex classes.
Try the simplest thing first, and then think about how you can make it better/closer to the expected.
You can always evolve from the simple later.

Best wishes.