by -Ninjex- on Tue Jan 22, 2013 2:30 am ([msg=72519]see Very Small First Program[/msg])

So yeah, I got bored, and I made a very small program in C++ in about 45m-1hJust started learning C++ and I'm not so l337 at programming.

Anyways, by the end of my studies I will make a version 2 which will be a full blown calculator, or way better than this.I plan on letting the user input how many numbers they would like to do math with, have a number selection instead of an operator selection for ease, (I could do that now) storing some of the variables in a enum and writing a switch statement for the inputs, and some other nerdy stuff that I either couldn't / didn't want to do the first go around.Anywho, I am just posting this so that if you are starting in C++ you can look at this and ponder.God this program is rough haha:

by Assassian360 on Tue Jan 22, 2013 8:38 am ([msg=72522]see Re: Very Small First Program[/msg])

Couple of suggestions you should follow:* Don't use goto at all.* Instead use functions and loops.* Perhaps if you want to try practice your skills at programming in the sense of writing a calculator you could try and work toward writing it to use reverse polish notation.

"Goto" is a command that is rarely used by developers in C++ for quite a long time now. It's more in there to support older software still. The big problem with using goto is that it doesn't follow the conventions of program flow that you will need to be using for anything more complex. It also makes it far more difficult to reuse code. If you want to reuse code with a goto you either have to duplicate the code or place lots of additional code to redirect back to another section after the code has completed. This becomes very very messy.

Functions and loops are essential basic programming concepts. Based on the code you have included you are familiar with how to use if statements. If you are following a course than typically loops will follow if statements in curriculum. And functions/classes soon after that. Somewhere in there too will be something about using arrays. If you're in a class learning this material it wouldn't hurt to try and go ahead if you are feeling confident so you can get a head start on these sorts of things.

You can look up what reverse polish notation is, but it is a typical simple programming task that is often used for combining concepts when learning C++. Once you have used concepts such as arrays you could have your code very easily handle multiple inputs on the single line to determine a result. For example in reverse polish notation you could enter:5 6 + And the result would be 11. This is because the 5 and the 6 would be placed into an array and then when the operator appears you would take the first two elements in the array and add them to get the result.

by -Ninjex- on Tue Jan 22, 2013 3:34 pm ([msg=72528]see Re: Very Small First Program[/msg])

fashizzlepop wrote:If you want to practice enums, sure, use a switch, but a simple if, else if block would do the trick especially since you have to call various functions based on the sign anyways.

I am doing it all for practice / fun... I might even go with the macro defines...I just started a youtube channel, and I am posting videos as I learn. It helps, since it makes sure I learn everything step by step and correctly. Thanks for the input again.