Explain our code so far in Triple X!

What does our preprocessor directive do?

Preprocessor directives are instructions for the compiler and they should ALWAYS be written at the start of the code. They include instructions that load other libraries of code before compilation.

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

It is used as the entry point and it is required to compile the program. Since main() is an int function, there needs to be a return statement of the same type. Return statements are outputs of the function, since main just needs a way to return and exit code, we just write: return 0;

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

In this program, we have just written the instructions that will be displayed at the start of our game, declared three const variables (a, b, c) and displayed each the sum and product of these variables.

Preprocessor directive - This line is telling the program to fetch us the part of the code library,
which in turn gives us console objects to worth with like cin, cout, etc, and some other stuff.

The main function is here because it is a necessary start of every c++ code, without it we couldn’t compile or run the code at all, and it points to the “meat and potatoes” of the code, the code itself (maybe?). The return statement tells us to exit the program without errors.

The expression statements are lines of code that have a ; at the end but are not declared (maybe?)

Our first expression statement paragraph is outputting strings of code to the console and separating the two strings.

Our declaration statements are declaring our variables and assigning values to them.
Const int is declaring a variable as unchangeable and then we’re adding value numbers to the variable.
After that we’re declaring variables that are sum and product of our a, b, and c variables.

Last paragraph of expression statements is printing that sum and product broken with lines in between.

The directive sets the initial difficulty and increases the difficulty each time its successfully completed. The main function is the governor before the game actually starts and the return statement is a loop to progress the game. The expression statement tells what happens to the user in the game, either pass (going to the next level) or fail (clearing the fail message. The declaration statement is upon successful completion of the game.

The preprocessor directive instructs the compiler to copy in iostream code before compilation.
The main function is the entrypoint to our program.
The first set of expression statements output text strings to the terminal on two lines.
The declaration statements declare and initialize 5 constants.
The second set of expression statements output the the sum and product constants on separate lines.
The return statement is our programs exit point.

Preprocessor Directive: Contains code written/compiled that we call into the current code; external code that the Main Function is dependent on

Main Function: Contains the code we are writing

Expression Statements: Contains code that interacts with terminal

Declaration Statements: Contains code that declares values/variables for Expression Statements

Return Statement: Turn the whole thing off.

the preprocessor code is code that is written somewhere else that we put into ours.
The main function contains the code we are writing.
Expression statements contain code that that will tell the user if they pass the level.
Declaration statements have the values for the second set of expression statements.
Return statement stops the program and returns 0.

The preprocessor directive is needed to establish the correct source program and makes it easy for programs to compile and be changed.

The main function is needed in order to write our lines of code. It is the main function of our program and it is needed in order to make the lines of code execute.

An expression statement is one that declares anything that we print to the terminal.

A declaration statement is one that declares a variable.

Our preprocessor directive gives our compiler a task to perform before compiling our code. In this case, it’s told to include the code from “iostream”.

The main function is “called” even though there isn’t any code calling it, because the compiler knows that the function main “needs” to be called to start our program. Returns an integer (a “whole” number), main is expected to return 0 on success.

Our “console output” expression statements output our text to the console.

The declaration statements declare the "const"s a, b, and c. As well as the const sum and product. The values of sum and product use the values from a, b, and c "const"s.

The second section of expression statements outputs the values stored in our "const"s.

The return statement returns the value right of “return” in this case “0” which is evaluated to be a success by the main function

  1. Preprocessor directive is importing all the functions written in iostream into our code.

  2. The main function contains all the methods to be executed inside it and the return statement indicates that the code has run successfully.

  3. Our expression statements are printing out the intro of the game and the values of the variables.

  4. Our declaration statements are declaring and initializing the variables that we are going to use.

I hope I am correct. :smile:

The preprocessor directive imports libraries into the script.
Any code inside the body of the main() function gets executed when the code runs.
The return statement exits the program.

Iostream:
Code pulled from another library

Main function:
Needed so that the code can be ran

Declaration statements:
Statements where constants and variables are declared

Expression statements:
Code ending with a semicolon

Return statement:
Needed to see if an error is present in our code, if the compiler returns 0 there we no errors but if anything that isn’t 0 is returned, an error is present.

add an external library, in this case, we are using iostream which allows us to write and send text to the terminal.

We have the main function to form a set of arguments. The return statement is used as an exit status for the operating system to know whether the program was run successfully or not.

Our program is using the Preprocessor Directive to print the expression on the terminal. The Declaration has three variables a, b and c that are calculated and printed with the variable int sum and int product, returning zero.

What does our preprocessor directive do?
Includes code that has been writing by other programmers to facilitate our work.

Why do we have a main function?
Because without its is impossible to execute the instructions in our code.

What does it’s return statement do?
The return, allows us verify that there are no errors.

Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.
The program print lines of text, add values to our variables, then print this values, and finally return 0, to verify that there are no errors.

Hi. Course log journal :smiley:

Preprocessor Directive - possibly the link to the chunks of code that are used in Expression Statements.

Declaration statement is the part where we are reserving memory which will further be use to store data in variables or constants.

Expression statements is a part where we are operating with memory and “tools” we’ve got from declared preprocessor directives.

Because the main() function is a type of integer, it needs to return a integer number. So if the function executed correctly and there where no errors in the expressions statements or declaration statements, then 0 will be returned which means successful execution.

So if I understood this correctly, the pre-processor directive is crucial for accessing prebuilt code made by other programmers, so for example without #include we wouldn’t have access to stuff like the namespace std…
The main function is very important for the compiler to compile your program, without it, it will return an error, and the “return 0” is there to tell the computer that we have successfully run our program I think, since we are using int before main we have to return an int at the end of our program (hence the 0).
Finally the expression and declaration statements are pretty self explanatory, these are what we use to either declare new variables… or simply write new statements that tell the computer what to do.

Preprocessor Directive: such as #include includes the std library. This is how we are able to include statements like std::cout << std::endl; to call functions from the standard library in C++.

Main Function: int main() is a required function that all C++ projects must have, otherwise you will get an error. It is the first function that the compiler looks at.

Expression Statements: These are statements that we use to output things to the terminal like strings, or outputting the calculation of variables. An example of an expression statement is std::cout << std:: endl;

Declaration Statements: These statements are used to declare or define variables in our code. An example of this is shown as int a = 4;

Return Statement: This is used to find problems in our code. If the return statement outputs a 0, then our code is executing properly, any other number being returned signals an error in our code.

The preprocessor directive imports code to include the input/output stream. #include can be used to import various libraries to enhance the functionality of your code.

The main function is what processes the main program, it can branch off into other custom made functions but will return to the main function. When the main function returns 0, it means the program has successfully executed and exited.

We start by writing some instructions to the output stream so it will display on the monitor, using std::cout. We are also able to break the line of text (string) by using std:: endl;

Next we declare 3 integer constants that will be used in the game and will not change their value at runtime. Additionally we have created constants for the sum and product of the 3 integer constants.

Finally we use more expression statements to output the values of the sum and product integer constants.

The return value of 0 ends the program.

It includes the library called “iostream”. We need this library in order to stream text.

We have the main function in order to execute our code, without the main function, our code will not be able to execute. We also have the return statement to check for the successful execution of our code. This happens if the main function returns the value 0. Any other value means failure.

The first expression statement we wrote streams or writes to the terminal a bunch of characters. In other words, text. We also included an expression statement that ends a line and moves to the next one. Next, we declared a bunch of variables that have stored data in them. These declarations are called declaration statements. With these variables, we can finally stream the values of our variables in the form of characters.

Preprocessor directive is to get libraries of code to use in our own.
Main function is where the program starts.
Declaration is assigning a value like the numbers we did and expression is where we tell the program to print texts or do a math operation and always end with a semi-colon.
Return statement is if the code ran successfully(i’m not sure if this one is true.)

What does thue preprocessor directive do?

It makes the computer aware we’ll be using prewritten code

Why the main function?

It’s the main part of a program and the starting point of every code. It’s the place where the computer looks first for instructions, and it’s where the code ends.

Return statement?
It confirms the code has been ran properly.

Expression statements give communications for the users, declaration statements- for the computer

Privacy & Terms