0 Members and 1 Guest are viewing this topic.
if (torch == 0){ cout << "The tunnel is too dark to explore.\n"; goto ex;}
if (torch == 0) { cout << "The tunnel is too dark to explore.\n"; goto ex;}
if (torch == 0) { cout << "The tunnel is too dark to explore.\n"; goto ex; }
if (torch == 0){cout << "The tunnel is too dark to explore.\n";goto ex;}
Hi iNk&Venom,I'd consider this pretty good for just starting!All of your program is in the main function; if you want to make it easier to read you can separate things out into more functions. For the mostpart you could translate your code to C easily (cout -> printf, string == -> strcmp, etc). Eventually you'll try to do object-orientated programming; which is a whole new paradigm.I'd suggest looking into for and while loops. I started out using goto's as well; and they even exist in C# but replacing gotos with loops really do make the code easier to follow. Keep learning!
this isn't at all the sort of thing that c++ is designed to do. c++ is a language made to work with complex, constantly changing projects in a way that remains both fast and reliable. furthermore, c++ is not at all a good language for a beginner, as it is jammed full of advanced features that are fantastic for professionals but make it very difficult to understand for anyone else. you have to approach the language holistically, learning basically everything at once, or you'll never get what things are doing.if you really want to learn c++, my suggestion would be to first master c, so that you at least know how basic program flow, like loops, conditionals, breaks, and cases; basic pointers; scope; headers; functions; and data structures, like arrays, structs, enums, etc, work. if you don't understand all of those perfectly you'll never get anywhere with c++ and will end up abusing it in ways it's not meant to be used. (EDIT: if you happen to have a calculator, then axe is an even better place to start, from which you can move on to c and then to c++, because the simplified instruction set and easier to understand approach to pointers [possible because of the calculator's simpler memory layout] are more beginner-friendly) if you want to write a program like this one, though, that's mostly text manipulation, go use a high-level scripting language. i'd recommend perl, because i hate python, but most people disagree with that EDIT: also, as a word of warning:Code: [Select]if (torch == 0){ cout << "The tunnel is too dark to explore.\n"; goto ex;}is the usual way of writing a statement like this, andCode: [Select]if (torch == 0) { cout << "The tunnel is too dark to explore.\n"; goto ex;}is also acceptable (and the way i prefer it). evenCode: [Select]if (torch == 0) { cout << "The tunnel is too dark to explore.\n"; goto ex; }is sometimes used for really small statements. if you ever send a program withCode: [Select]if (torch == 0){cout << "The tunnel is too dark to explore.\n";goto ex;}in it to another programmer, however, he will almost certainly label you as an idiot.
shmibs is right on a few aspects...c++ isn't for beginners, however I never learned c first. I came from a java background. Pointers are going to be something you want to learn they are pretty important and powerful. Scoping and headers are probably another good area to read up on. How classes work would be in there too. Object Oriented Languages are awesome...As for where to place the brackets in your code like in the four examples that shmibs gave. As he said the first two are usually the standard way of placing them. Go with which one makes it easier for you to read your code.
Funny I came from a Java background too, then I realized it was... Well... Quite a selfish language. So now I use C# to make games for PlayStation network
QuoteFunny I came from a Java background too, then I realized it was... Well... Quite a selfish language. So now I use C# to make games for PlayStation network I've been doing mobile development for the last few years. Mainly Objective-C, I had also done some homebrew development on a psp back when it first came out. I really like what Sony has done in relation to their whole SDK policy for the mobile and Vita stuff.