Is it any difference writing the whole code of your own functions before the main?
How can I edit my code on this site properly?
My code is the following:
#include "stdafx.h";
#include <iostream>;
#include <string>;
using namespace std;
//Introduce the game
void PrintIntro() {
constexpr int W_LENG = 5;
cout << "Welcome to the Cows and Bulls game\n";
cout << "You must get my guess word that is an isogram and it's long " << W_LENG <<" letters\n";
cout << "An isogram is a word in which every letter appears only one time\n";
cout << "Let's start the game\n";
return;
}
//Execute the game
int main()
{
PrintIntro();
string Guess=" ";
while (Guess!="**")
{
cout << "-----------------\nWrite a word: ";
getline(cin,Guess);
cout << "You typed: " << Guess << endl;
}
cout << "I'm ending the program...\n";
return 0;
}
Is it any difference writing the whole code of your own functions before the main?
I assume you are referring to defining the PrintIntro() function before your main() function vs just declaring it, and then defining it (writing all of the code of the function) after main. If so, there are a number of differences. To be honest, it won’t matter in such a small application, but there can be some performance implications for larger projects, particularly when you get to classes and you start creating class header and definition files.
From a stylistic sense it also makes sense (at least to me) to be able to see all of the function declarations in one section, and then reference each function definition elsewhere. Eventually, the code in this project is broken into multiple files, and you will see the value of it there.
Your second question…are you referring to formatting code as you post on the forums? I use the icon that looks like </> right over the text box to preformat my code…not sure if you are looking for something else.