Explain our code so far in Triple X!

What does our preprocessor directive do?

It loads previously established code into our program for our use.

Why do we have a main function?

To initialize and execute our code.

What does the return statement do?

It tells us when our program ends and whether there were any errors.

Expression statements tell us what our program is doing and declaration statements declare several different variables to help our program complete its task.

Our program so far can print lines of text, then take the sum and then product of our a, b, and c variables and print them to the screen.

  1. The compile will grab some code from another library, so it can function and use it in our code.
  2. The main function has the parts and pieces that c++ requires to even compile, if not there it will throw an error. The return 0, forces the compile to stop so it doesn’t continue to run and run, then bog down the computer.
  3. Our declaration statements are declaring variables, which are integers, and constant. Our expression statements are how we want to express the results on the screen.

So here’s a screen shot of my code. Changing it up a bit to adapt to a game I’m thinking of.

Our preprocessor directive loads code from a library so we can use it in our project.

We have a main function because that’s the function that the program needs to run. Every C++ project must have a main function.

The first expression statements print those lines of code to the console to give the player a background on where to begin the game.

Then we have the declaration statements, which assign some values to the variables we declared to use them in our code. Specifically, we use them to print the sum and the product of those variables in the end.

Finally, the return 0 statement in the main function to indicate that everything went well.

Our preprocessor directive instructs the compilator to include the code which the header file iostream contains, we do this in order to use some functions there defined which allow us to communicate with the command prompt(like printing and taking input).
We have a main function because it’s the entry point of every c++ program, in other words, it’s where the OS will look for the instructions to execute, it is also supposed to return an integer(0 if everything run succesfully) to the OS.
Our first expression statements print a brief introduction to our game, the declaration statements it’s where we declare and initialize the variables we are going to use throughout the program(even though we also use the const keyword to turn the variables to constants, thus, preventing them from ever changing their value during the runtime of our program). The second series of expression statements are there in order to print to the command line the values of two of our previosly defined variables.

Preprocessor directive
Adding external library to access the std namespace and use the console out, method

Why Use main()
This is the start of our little program.

Expression Statements
These are used to output to the console (speaking to the user)

Declaration Statements
These are assignments of variables that we will use in the program.

Return Statement
This is the final output for the program, 0 mean no errors or successful.

Alright so the preprocessor drive includes code from another library which help us compile our code.
Without the main function our program would not work. The return statement of the main function indicates to us if there were any errors. If the function returns 0, then the program has no errors, else, should the program return any other number it means it has errors.
Alright now we come to the lines of text.
The first expression statements express a couple of messages, each on separate lines.
In the declaration statements we declared the variables a, b and c with their constant values.
Then we declared their sum and product, assigning them the proper values.
The second expression statements print the values of the sum and product, each on a separate line.
The final expression, return 0, checks for errors.

Preprocessor Directive: Is an instruction to the compiler to access the code within the header file, in this case, “iostream.”

Main Function: Declares a function that returns an integer (return statement). Without the main function, the code won’t work.

Expression Statement: Any string or block of statements ending with a semi colon. Based on previous examples of expression statements, these strings seem to be a sequence of outputted characters like “Hello World!;”

Declaration Statement: Stems from the expression statements, but declares the values of variables like “int a = 4;”

Return Statement: Notifies the compiler that there are no errors in the code, hence the value of “0.” The return statement also signifies the end of the code.

Preprocessor Directive - Import and pre-set for c++ functionality

Main function - The main control of the program

Expression statements - Debug that can be use the check at particular stage of the program

Declaration statements - This part of the program will do any sort of operations depends on the purpose. But cannot view or see the result from them, unless you use expression statements to debug

Return statement - The must of most functions because after a function executed it must response(return) back some value.

Our preprocessor directive loads other code that we need to run our program. Our main function is calling all of the statement written inside of it. Our first expression statement is displaying information to the user, explaining the game. The declaration statement is setting our constant variables. The final expression statement is displaying the sum and product variables which we declared in the declaration statement. The return statement is returning nothing to the terminal if the program runs successfully.

It will load needed libraries and preprocess them before compiling our code

We need main() to run our code. Main is a type of int so it requires return statement which contains int. If we don’t add return statement, the compiler will add it automatically to the code.

  1. There is a couple of expression statements to print out some text.
  2. We declared a couple of variables and assigned some values to those variables.
  3. We declared variables for sum and multiply.
  4. We made expression statements to print out the sum and multiply.
  5. Then we return value 0 to see everything went as excepted.

is a pre-written code, #include makes sure to include iostream into our code.
int main () tells the compiler where the beginning of the code is
The expression statements and declaration statements are the true code, telling the compiler what to do
the return 0; is the end of the code, if there were no errors it will return 0

  1. What is #include doing?

#include is bringing in a ‘glob’ of code called ‘iostream’ from somewhere else

  1. Why do we have the main function in our file?

This is so that when the file is executed, we can direct the computer (and/or compiler?) to know what to do first upon execution.

  1. What are the Expression Statements doing in terms of our Gameplay?

The Expression Statements are Leveraging ‘cout’ functionality (contained in whatever ‘std’ is) to print text to the screen

In the first expression ‘block’ we are introducing the player to the game world and prompting them to enter a code.

In the second expression ‘block’, we are simply displaying the sum and product variables we created in the Declaration Statements.

  1. What are the Declaration Statements doing in terms of our Gameplay?

The Declaration Statements are creating variables and setting them to their initial values

In this case, the variables are being declared as ‘const’ (Constant) variables, which means we can’t alter them after declaration.

In gameplay terms, we’re setting three numerical values (a, b, c) and also setting the sum and product of those variables as the ‘sum’ and ‘product’ variables

  1. Why do we have the return statement in our main function?

I think it is required to return something from any function.

I’m not exactly sure why we return 0, maybe it is an accepted standard to return 0 if we don’t need to return anything from a function.

What does our preprocessor directive do?

It tells the program what to take into consideration or to run before it starts

Why do we have a main function? What does it’s return statement do?

We have a main function for every c++ program needs one. C++ programs do not run without a main function. A main function is build op out of statements. I think a return statement makes the program return to a previously written main function or to it’s former state which can be its on-existence…

Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.

An expression statement ends with a ; , a decleration statement declares something, like the value of certain variables or what counts as a variable. In our expression statement we stated what should be shown on the te screen and in what order it should be shown. With our decleration statements we declared some inter variables

What does our preprocessor directive do?

The preprocessor directive brings in an external library so that we can use VS Code to write in C++.

Why do we have a main function? What does it’s return statement do?

The main function is needed for the program to run. The function executes everything in the function body (?). The return statement returns a value of 0 to tell the computer that no problems occurred during the running of the program.

Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.

The first expression statement prints the setting/story to the terminal. The declaration statement declares all of our variables, like a, b, and c. It also declares the mathematical expression we use them for. The second expression statement prints the sum and product to the terminal.

-Enrico

The preprocessor directive basically tells the compiler to adds code from a library.
Because this is the part of our code which tells the compiler to execute the code inside to create our program.
The return statement tells the operating system whether the program successfully run or not.
The expressions inform the user what to do and give out the results.
The declarations allocate memory locations for use, fill them with data and provide operations which will be performed on the data.

the preprocessor directive tells us where to pull the code from.
The expression statements tell us what is happening in the out put of the code (wether it is a sentence or space)
The declaration statements labels variables so that they are expressed properly and the return statement ends the code.

I believe the preprocessor directive is an instruction to the compiler that is done before anything else (in this case pulling and using a library). The main function is required in all code and is the back bone (maybe?). The return statement I also (I think) a required bit of code that is returning an integer to the terminal. The expression statements we have either write text out to the terminal for the reader/player, or make it easier to read in the terminal by causing new lines and organizing blank space. The declaration statements set constant variables, and then make new constant variables that are the sum and product of the previous constant variables.

My Pre-Processor Directive loads a library of code before my code is run. My Main Function tells my computer that I am running C++ code and my return statement returns my computer to the state that came before running my code.

An Expression statement tells my computer to express a command and a declarative statement declares a command.

The preprocessor directive tells the computer to load a library of code before my written code starts to work. Every program requires a main function or else the code will not run. The expression statements are used by the computer to express content. The Declaration statements are used to declare values of variables. The return statement returns a default value to the computer at the end of the function so that it stops loading.

Privacy & Terms