Originally Posted by
dark21
thanks guys. by indent you mean add this right
<<" lines of code ";<<
or do you mean i should dobule space my code or do both?
Indentation is used primarily for your benefit. You indent and space your code so that it's easy for YOU to read and navigate. Your compiler doesn't care whether or not you indent your code or write your entire program in one huge line. However, with indenting styles, if you intend to write code that other people are going to read (for example if you are working as a coder, or are posting your code to a forum for help/advice/kudos) it is advisable to conform to one of the standard indentation schemes.
At the very least consistent indenting will enable you read your own code quicker and spot issues that you may miss if it is flat.
non-indented:
Code:
using namespace std;
int main( void )
{
srand(time(0)); // seed random number genrator
string name; // used to store string names
bool end = false; // used to test if the user chose to quit
bool lost; // used to test if the user lose the game
[...sic]
cout << "\nYou have " << archers
<< " archers,"<<catapults
<<" catapults, and "
<< swordsmen << " swordsmen.\n"
<< "\nGermania has " << g_archers
<< " archers,"
<< g_catapults << " catapults, and"
<< g_swordsmen
<< "sworedsmen.\n";
do // pre battle loop
// that are being used
{
int i = 1;
if (archers > 0 &&
((archers - archers_sent)!=0))
{
archers_menu = i;
cout << "[" << i << "] send Archers\n";
i++;
}
indented (this is the style that I use):
Code:
using namespace std;
int main()
{
srand(time(0)); // seed random number genrator
string name; // used to store string names
bool end = false; // used to test if the user chose to quit
bool lost; // used to test if the user lose the game
[...sic]
cout << "\nYou have " << archers
<< " archers,"<<catapults
<<" catapults, and "
<< swordsmen << " swordsmen.\n"
<< "\nGermania has " << g_archers
<< " archers,"
<< g_catapults << " catapults, and"
<< g_swordsmen<< "sworedsmen.\n";
do // pre battle loop
// that are being used
{
int i = 1;
if (archers > 0 &&((archers - archers_sent)!=0))
{
archers_menu = i;
cout << "[" << i << "] send Archers\n";
i++;
}
[....and so on]
The style you use is personal preference and a lot of editors automatically indent for you.