manutd - Thanks for that bit of code on indenting...thats kinda what I was looking for. What other ways are there to indent? Anyone know of a link to some advice on that? Thanks for the input everyone!
manutd - Thanks for that bit of code on indenting...thats kinda what I was looking for. What other ways are there to indent? Anyone know of a link to some advice on that? Thanks for the input everyone!
Another way (somewhat different):And another:Code:for (int i = 0; i <= 10; i++){ if (i %2 == 0){ cout << "It's even!" << endl; } else{ cout << "It's odd!" << endl; } }Check out this site.Code:for (int i = 0; i <= 10; i++) { if (i %2 == 0) cout << "It's even!" << endl; else cout << "It's odd!" << endl; }
I'll run it through my compiler when I get home I'm at school. What is wrong with the cout statements?
You say something like this:This won't compile. MinGW gives this:Code:cout << "new - New game << endl "exit - Exit game << endl << endl;
8 C:\Dev-Cpp\cprog\main.cpp missing terminating " character
9 C:\Dev-Cpp\cprog\main.cpp expected primary-expression before '<<' token
10 C:\Dev-Cpp\cprog\main.cpp missing terminating " character
This will compile, but not what you want:This outputs:Code:cout << "new - New game << endl exit - Exit game << endl << endl";
new - New game << endl exit - Exit game << endl << endl
What you want:Code:cout << "new - New Game" << endl << "exit - Exit game" << endl << endl;
might be even more appropriate. All of the endl's are unnecessary. IMO adding newlines into the output string is clearer.Code:cout << "new - New Game\nexit - Exit game\n\n";
Yes, but I was just trying to preserve his original code.
Instead of endl new line '\n' works equally as well.
@manutd I approve of your indent sytle, for me its three spaces to every indent. I hate tabs, they annoy me. I only use tabs if I really have to. But manual indentation sticks in your brain more than hitting tab. Of course it all depends on how the OP's IDE is set up
Double Helix STL
> Instead of endl new line '\n' works equally as well.
I agree. However let it be said that, endl may be useful for debugging purposes. Along with ends or flush, it flushes the buffer. When using cout for debugging purposes, if the application crashes the buffers will not be flushed and this may give the wrong impression on where the program crashed.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
@swgh: I just set the settings to make a tab 5 spaces (I know, it's wierd) and then use tabs.
That help on that code was cool! I was so tired adding that in I wasn't thinking and never closed the quotes lol. As for new line... we went over stuff like '/n' and '/t' etc, but I just used endl since I was more comfortable with that as a low-level programmer. I'll try to do better with my syntax...I know it must hurt seeing my code. Anything else you all could think of that I should keep in mind is all great. I take advice very well actually.
One thing (maybe a typo on your part, I do this often): '/n' != '\n'.
>I know it must hurt seeing my code.
Dont put yourself down like that. Everybody has to start somwhere. We all make mistakes, and asking when you re unsure is one of the best ways to learn, especialy in programming
Double Helix STL
Well... that looooong code... it did hurt
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
But honestly, compared to some, this is awesome You've learned from this, and you made a try before coming to us. Continue learning and you'll do well with C++.
>Well... that looooong code... it did hurt
Tut tut mario.... its a work in progress..
Double Helix STL