i think I did but but I need someone to judge it before I sell it on hackforums.
my friend says i should adopt his coding style, but i dont think i need to. I mean no offense, but his code looks horrible.
You don't know the issues involved with the labels when it comes time to debugging. Your program technically doesn't flow from the top down like C++ was designed to. In a typical C++ program, you start at main() { and read down until you reach } but in yours, you're bouncing all over the place. There is also no purpose to putting SRO for labels since it's all going to be getting used as well. You were also talking about optimizing your code, yet you use strings for user input of integers, you use complicated functions in your if statements when you're comparing, when you could have just used a switch.
I'm not trying to destroy you or your code, just simply point out the improvements you asked for. There is a reason why everyone suggests you using functions, and it's not just because we think it's right. Plenty of people here, myself included, have had their share of headaches with programming. I've dealt with labels before and I swore to never use them because of what I had to go through.
You also create a lot of variables at the beginning of your code, causing your program to use a large, relative to the simplistic nature of the program, chunk of memory for variables you don't use, or may never use. So I don't feel that your code optimizes much of anything. And doesn't improve over anything when it comes to readability sacrifices.
so my friend was right about my code? I'm using the style of coding they did back in the 80s with goto?
then why do the have goto if it's bad? What makes his coing better than mine? His looks bad to me.
Do you realize how much technology has changed in 30+ years? Technology was limited back then, but even as far as I know, labels were considered bad back then, but they have their purposes. And since C++ is supposed to be backwards compatible with C, it's still in the language.
Also, I don't know what your friend's code looks like, but with C++, you can have two coders who have the same style and their programs look completely different. There is nothing wrong with limiting the number of lines your code has, I do it, but do it within a sense of coding. If you haven't learned functions yet, learn them. There is so many advantages of functions that labels don't offer.
this is his project from a month ago. the reason we got into a fight was because he is learning about optimization in c++ and was complaining about how bad mine was. it pissed me off
There is a lot of issues with his code, but this isn't the discussion for it. He seems like he is also much further in the language than you are. I also don't like his code much myself, but even the most elegant code is ugly to some people.
As for tutorials, this site has a great beginner tutorial. You can skip the parts you know, and read the parts you're unsure about, and really read the parts you don't know. The tutorial is located here: http://www.cplusplus.com/doc/tutorial/
There is a lot to learn, and learning a good "style" isn't easy either.
I personally use the 1TBS, or 1 true brace style. But I also tend to break else scopes on a different line than the proceeding if SRO with a 3 space indentation. I use AStyle to keep my code formatted so I can easily read it.
There are other styles such as naming conventions and others.
Edit: Also, don't worry about using arguments against him, he'll more than likely rub your bad techniques in your face or your limited knowledge. I'd just focus on expanding your knowledge and finding a style that you like. C++ is a fairly unique language in that you can make your code look however you want.
Gotos are fine in the end but they lead to really terrible looking code that is a nightmare to manage in larger applications.
In the end every loop is converted in to a goto or more specifically a jump because that it how the CPU coding sets work. Loops just make things so much more pleasing to read and you should use them if you want to be taken seriously.
Modern day compilers will take care of the optimization as long as your code isn't redundant or poorly designed. If you are that worried about optimization than why not code in assembly where you can directly code with the CPU's instruction set? You won't be able to use it on different CPU's but who cares, it's optimized, right?
@TheBestHacker
He may not have meant optimize it as in the sense of speed/efficiency, but rather optimizing it for better readability. You can always improve readability.
@IceThatJaw
Gotos are fine when needed, but with as much syntax that exists in C++ now, it's very rarely needed. And yes, loops are essentially a goto/label, but that doesn't mean that they should replace functions as TheBestHack's labels do. And most compilers will optimize redundancy and poor design. But they have their limits as well.