Explain our code so far in Triple X!

To start off the preprocessor directive is essentially calling sections of code from other libraries.
The main function is what the entire program requires to actually run. The return statement is what finally ends the main function.

Lastly, the expression statements work to output what the game is about and what the user is doing. With these we then have the declaration statement which is giving each variable a value.

The directive is just like in c# using… what ever. It allows access to a library.
We have a main function because with out it cpp will not know what to do.
Return is a close program.
The first part of our expression statements are to print a string to convey info.
Our declaration statements are to make a const var of type int a,b,c.
We then make new const vars of type int by using + and * to total numbers respectivly.
Then out put sum and product. and close program.

The preprocessor directive is included to tell the compiler to use a file filled with code and its at the top so it can used first. Next, the main function is the starting point for c++ and without it, the program won’t build. The return statement resets back the program after its has been successful. The declaration statement state the variable that are being used and the expression statements write out what to do with the variables and to be displayed. I GUESS

The preprocessor directive includes outside code in our file for necessary functionality.

A main() function is required for our c++ code to compile, as it is the starting point for EVERY c++ .exe file. It’s return statement returns a numerical value to indicate success and error codes. In our case, it is only returning 0, which is the “no errors” code.

Our expression statements have set up the background story of the game for the user, while our declaration statements are working behind-the-scenes to store data that is necessary for game functionality.

So yeah, let’s see if I can nail this:

  • The preprocessor directive gives the compiler the command to use a defined library before compiling the rest of the code.
  • We need the main function in order for our code to compile at all. The main function is an entry point and basically the first thing that any computer will look for. The return statement gives us a numerical value that indicates success or gives us any errors. In our case it gives a 0 that indicates that all is good and the program exits.
  • An expression followed by a semicolon is an expression statement. They are mostly used during this course to either print out some text in the Terminal or change the value of a variable. A declaration statement is used when we are declaring values for variables for example.
1 Like

What does our preprocessor directive do?

It includes a library to your code before compiling

Why do we have a main function?

the main function is the entry point for the program, without it the program will not build

What does it’s return statement do?

the return statements indicates that the code was successfully built and compiled

Before starting the main function of the program it will start first with the preprocessor directives in this case in the code it will include first the iostream library before starting the main function.

The main function is responsible on what will the program will do.

Return statement is the one responsible to return a value to the operating system to tell it that no error was found in running the program otherwise it will return a value other than 0 that will result to an error.

First the expression statements that displays a text explaining the scenario of the game, then the declaration statements of the variables. Lastly output the contents of the variables.

1 What does our preprocessor directive do?

The preprocessor directive makes functions that are in other libraries load into or be accessible by the compiler so when they are called in the code that they can be understood. This saves on space and clutter.

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

The main function where most of the work of our code is done. When executing its where the code truly starts. The return statement gives a value determines the end of the execution of a function.

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

The expressions we’ve provided give textual statements that add flavor or information about what is occurring. The declaration statements establish variables that can be called later to perform various actions. For example, the variables are being called to perform mathematical actions to form new variables from the previously declared ones. Then expressions statements are being used to print the values of the variables when the code is compiled and executed.

Why is myvariable = 5; an expression and const int a = 4; a declaration?

They seem the same to me.

Thanks.

What does our preprocessor directive do?

Adds the contents of the iostream library to our file

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

Each program must contain main functions. This is where the compiler starts working with our program.
Return statement returns 0 if your program run successfully. Otherwise it return other number.

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

  • First we print text to console
  • Then we define constant variables (a, b, c, sum, product) and we assign an initial value
  • We print the sum and product of values a, b and c
  • At the end we return 0, as a sign of successful program execution

int a = 4;

Here you declarate to compiler that ‘a’ is variable of type int.

myvariable = 5;

Here you only change value of existing variable, so there is nothing to declare.

The preprocessor directive includes the libraries that are going to be used in our code.
We have a main function because is needed to execute the program we are writing.
The return statements gives us a value of the function type, in our case an int of value 0.

Our expressions show the texts of our game in the screen and it shows the value of some declared variables. First explaining what’s the game about then showing up the sum and the product of our 3 declared variables.

I see it like this:
Preproscessor directive << Here we can prepare or say to the copiler we will need those functions, the functions of this libraries, and also when we compile we convert it in binarry.
Expression << here is what we would like to show to everybody, outside on the screen
Declaration << here we programme our things, our programme, all that he need to do
Return 0 << Sounds good !!! means that we reach that our program finished, maybe it does not work as expected but it finised :grinning:

Preprocessor Directive

It is used to load a pre-written code from outside.

Expression Statements

They are used to write code which contains text that will be visible to the user when he runs the program or to give spaces between the lines of code.

Declaration Statements

They are used to declare values to variables and to perform calculations on them. They will not be visible to the user who runs the program.

Return Statement

No idea :stuck_out_tongue:

Our preprocessor directive tells the program what code is to be compiled.

Having a main function can let us have variables, expressions and data to get the program to read it and run the program. The return statement is read by the program if their are errors or error free, then closes the program.

Our first expressions has strings with end lines that skips a white space between the two strings. Our constant declaration statements “a”, “b” and “c” is initialized by numbers. The other declared variables that are the “sum” and “product” is initialized by statements. Our second expressions gives the output of the “sum” and “product” variable with end lines skipping a white space between them.

#include <iostream> //Preprocessor directive: instruction given to preprocessor
using namespace std;

int main() //main function = the actual function which is executed
{
    //Expression statements = expressions followed by semicolon;
    cout << endl;
    cout << "Hello newbie! New guys are just newbies here, not cops." << endl;
    cout << "Now introduce yourself to your chief, rookie! Who are you, just another disappointment?" << endl;
    
    //Declaration stastements = declaring variables
    int a = 5;
    const int b = 10;
    int c = 15;

    a = b - c;

    int sum = a + b + c;
    int mul = a * b * c;

    cout << sum << endl << mul << endl;

    return 0; //return statements: returning (finishing) function
}

io in iostream stands for in and out.

Preprocessor directive: The #include is pulling data(?) from another library.

Without the Main function the program would not run. It’s the meat of the program so to speak.

The Expression statements are what the player or user would see while the declaration statements are not seen by the player or user and act as a sort of rules for the rest of the code to follow

The return statement makes sure everything runs correctly. If it returns 0, we’re good to go.

What does our preprocessor directive do?
It helps us to use the library made by another person.
Why do we have a main function? What does it’s return statement do?
Main function is needed to execute the statements and declarations that we have already given. Return 0 is used to understand whether there is any error in the codes that we have written.

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

Expression statement means expression along with semicolon and declaration statement means that we are declaring variables that are needed for our code that we have written , which includes const int (a,b,c,sum,product) and atlast we will get the sum and product through the expression statement that we have declared

preprocessor directive: It tells compiler to run this piece of code before running anything else, it loads and allows us to use the functions and code that is “stored” within iostream library

main(): I believe it’s the “body” of our program, the program won’t be compiled and won’t run without it

expression statements: those are just statements that don’t declare any variables

decleration statements: they allow us to declare variables and assign or re-assign values

return statement-it tells us that everything has run correctly and it returns value of 0 to end the program

Privacy & Terms