Explain our code so far in Triple X!

it tells our compiler to include a library prior to the code being compiled

the main function tells the compiler that all of the functions contained within it are the elements that make up the executable

expression statements that we have written so far tell the compiler what we want to see displayed on the terminal, declaration statements give the values to each of the integers that we have created in the code and allow the compiler to know what those values are so they can be correctly displayed

Exactly, that! Lol I’m too lazy to type.

1 Like

Preprocessor Directive: I am gonna be honest, I still don’t know what it does.

Main Function: It’s basically the program’s core that we need in order to have the building blocks for our game here. The return statement just takes our code and gives it back to us in text in correlation to the expression statement. It also categorizes the main part of our code for how the game works.

Expression Statement: It gives us the results of our code in text on the terminal to emphasize a narrative and to return the numbers we have our integer variables set to in constant.

Declaration Statement: It’s the under the hood work, setting what the variables are that are then communicated back in text through the expression statements in our code after they are set.

What does our preprocessor directive do?

The iostream that is ‘#included’ is a prewritten program? I don’t know yet. I assume at this point that iostream is a program that reads commands like endl; and int to create a work space…

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

This likely means that there are non-main… maybe: tributaries? that we shall being forging…?
The Return statement is the ‘amen’ and no more digiprayers forth hence… unless the return is anything but ‘0’.

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

First we express text, mine is: “you’ve stumbled into a nuclear arsenal command bunker, and like a genius, you’ve accidentally triggered the launch sequence. now you must solve a riddle to defuse the launch.”
after expressions, code begins with declaration of variables using the command int
variables are a, b, and c.
then the sum of these numbers, and also the product of the three numbers are developed, and plotted out below the expressions.
At this point I haven’t gotten to the portion where the explanation of how the riddle is solved has been added to the program, but that should be easy now.

1 Like

oops, if you look close I added space by sum out and product out but hadn’t compiled yet before screenshot

The Preprocessor Directive (I’ve been calling it the PPD in my notes…is that okay, or is there something else it might get confused with later?) is taking pre-written code and adding it to the beginning of your code. I think this probably simplifies writing code since it will allow you to use other complex functions with a simple calling of a namespace instead of having to write them out.

The Main Function lays out the fundamentals of how our game will work

The Expression Statements are responsible for the text and visuals that are output by the terminal upon running the program.

The Declaration Statements are responsible for defining what the variables will be and how they are used in our code.

The Return Statement gives the operating system an exit strategy once the game has run it’s course.

1 Like

I had to refresh myself on the preprocessor directive! It pulls code that already exists prior to compiling the code we have written.

The main function is the sum, or overall purpose of our expression and declaration statements. The return statement signifies the end of the main function.

Our expression and declaration statements are assigning values to the variables and adding/multiplying before printing to the terminal.

  • David
1 Like

What does our preprocessor directive do?

It apparently includes code from another library, however where it pulls this code from I am unsure.

Why do we have a main function?

Apparently every C++ program has this, and it’s a way for the compiler to know where the program begins.

What does it’s return statement do?

Used to find errors. If it returns 0, there are no errors, anything other 0, there are errors.

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

The first expression statement is expressing a string of text.
The next Declaration statement is declaring the values of our variables used.
The second expression statement is expressing the sum and product of the variables into text.

1 Like

What does our preprocessor directive do?

It loads a library for us to use.

Why do we have a main function?

Because that’s the function first runs when the program initialized. So it’s basically the core of our program.

Our expression statements first prints the enterance lines of our code then our declaration statements declares some variable and after that expression statements prints two of our variables. In the end return statement ends our program.

1 Like

The preprocessor directive I think essentially an order or set of instructions given to the compiler before it works through the rest of the code. Like the include statement, it acknowledges the fact that we’ve just included a library of information before taking the rest of the code into account.

The main function is used to tell our program to start and where to do so, and the return statement is there to tell us whether or not our program has run and exited successfully or if there is a hiccup somewhere (if the number does not return as 0, for instance.)

So we’ve got declaration statements (like ‘a = 3;’ for example) that also are classified as expression statements, since they end in a semicolon. I think that’s correct? We shall soon see! As always, good luck and have a fine day, friends!

Very well put, my friend! Are you alright if I use this explanation in my notes? I found your description very comprehensible :smiley:

I think the preprocessor directive is you including code from another source.

The expression statement is what will be displayed when the code is compiled.

The declaration statement is telling us what the variables are.

Not sure about the return statement, wasnt it stated earlier its there to make sure our code is compiled correctly? thats my guess.

It loads codes from other files to the main file during the compilation process

The main function is the default function that is compiled by the compiler. It’s return statement serves to point to the computer wether the program has run successfuly.

Preprocessor Directive: This is where we give instructions to the compiler to do make an action before it even starts running the programm.
Main Function: This is where the programm starts.
Return Statement: It basicaly ends the programm.
Expression Statements: Every action that the programm has, besides the declaring of values at variables (also always ends with a “;”.
std::cout << “I am an agent”; This is telling the programm to output on our screen what is written in the quotation marks
std::cout << std::cout endl; -> This is telling the programm that it should leave a line between what was previously shown as an output
std::cout << a; -> This is telling the programm it should output the value of the “a” variable
Declaration statements: Declares values to variables.
const int a = 21; -> This is telling that the Variable “a” should always be 21 and that it cannot take another value, even if we try to change it.
int b = 2; -> This is saying that variable “b” has a value of 2.

The Preprocessor Directive pulls information and code in from outside header files BEFORE our code is compiled.

Our main function is essential for our code I know, but I’m not sure specifically why. I know it causes the code to trigger and with the return statement return a value of 0 to verify our code is working but I am not sure why it is needed.

The declaration statements define our variables and determine certain value to be used in our expression statements.

I do not know what the Expression Statements do beyond give information and feedback back to the user.

The return statement acts as a check to ensure that our code is properly functioning by returning a value of 0 to our function and ending the process.

This loads the header file (which is a library of code that can be used rather than writing it from scratch).

The main() function is the body of the program and is needed for it to execute. The return statement is ‘signal’ of sorts which tells the computer that “when a 0 is returned” there are no errors and the program can end, if not, then something has gone wrong.

The expression we have written is outputting code to the terminal as instructions to the user.

The declaration statement is defining our integer variables as well as using those variables within another variable (sum, product).

Currently the program outputs a text string telling the user what to do, defines our variables (a, b and c) as integers, defines two other variables that produce the sum and product of those variables. Then we print everything out and return a 0 to indicate there are no errors.

The Preprocessor Line brings in other lines of code for us (it would be like copy and pasting other pieces of code without having to actually do it)

The main() is the core of the program that is followed when we execute a program. Return 0 effective ends the code?

Expression statements form some sort of change or action for the program. Declarations are assigning (or changing) the values of variables.

Our non-declaration statements are outputting things to the terminal.

Preprocessor Directive
Tells the preprocessor what to change and/or include about our code.

Main Function
This function will be executed first.

Expression Statements
Prints to the screen and take input.

Declaration Statements
Adds memory space to variables and declare what value to store.

Return Statement
Returns a code to the console stating whether or not it was successful and, if not, how it went wrong.

The preprocessor directive takes already existing code located in the specific header file that is called. This must be called before any other code is written.

The main function is what allows our program to run. if we compile our code, and 0 is returned, we know our code compiles properly, otherwise, we know there is an error which needs to be fixed.

  1. we are given a few lines of dialogue, which introduces what is going on.
  2. we assign integers to specific variables in the code, (they can not be redefined since they are const int’s).
  3. We print out the variables sum and product.
  4. We return 0, this will help make sure our code is working properly. If the program does not return 0, something has messed up.

Privacy & Terms