Explain our code so far in Triple X!

Preprocessor directive instructs the compiler to add the codes from another library.

We have a main function because all c++ programs need a main function to run. The program cant run without a main function.

The return statement returns the value from the end of the main function to signal the end? Ill get it as we go along.

We declare our variables so that we may use numbers for the code to become super mega duper hackers? And the expressions are the lines ended in semicolons

It provides instructions to the compiler that will allow further code to be able to write to the terminal.

All I remember is that a C++ file always needs an int main function. I’ll read other comments in order to fully remember why.

It returns an integer, specifically 0.

The first 3 expression statements display 2 lines of text on the terminal, to introduce the player to the game.

Then, the 3 declaration statements declare what types of values will be assigned to their respective variables, and whether they are constant or variable.
Then specific values, of which their type must match the declared type of their respective variables, are assigned to said variables.

The 2 declaration statements after demonstrate that the 3 previous initialized variables can be operated together in order to initiate new variables.

The last 3 expression statements display the sum and product in their own lines through a modified line breaker code syntax which makes the code shorter and thus more concise.

The return statement, which is the last statement in the body of the function it is part of, returns a value, in this case an integer of the value 0.

Also, for fun points, each statement ends with the ; character as per the syntax of C++.

1 Like

What does our preprocessor directive do?

It tells the compiler what the groundwork for our program is.

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

The main function tells the compiler where our program must start excecuting
The return statement tells where and how the program should exit

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

We start with printing to the terminal the initial instructions for our game. We then assigned three constants as integers and given it three numerical values. We then assigned two constants with the product and sum of our three intergers and printed these to the terminal as wel.

1 Like

Hello everyone here.

  • #include is preprocessor and iostream is a header file so the #include will copy all the code from the iostream and get it include in our source code

+main is a function precisely it’s an entry point to every c++ program, without the main() would fail to start , it has a return statement which let us know that there no error if the return value = 0
+expression statement prints to the terminal
+decalration statement declares a variable with a type

What does our preprocessor directive do?

It’s predefined library we are using in our code

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

Every program in c++ need to have one. Compilator always will search for this one and start compiling from this point. We need return statement because “int” need to return a number. 0 means everything went well but any other value means an error.

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

First expression statements are code to display beginning of our story to player in the console.

Second expression statements are code to display values written in declaration statement.

The preprocessor directive includes code that is pre-written. It runs this code before running the rest of what we have written.

The main function is telling the compiler where we actually want to start. It communicates where our code is. The return statement ends the code and reads for errors.

Our first expression statements are printing the explanation of our game. The declaration statements are determining the values in the game, and the second set of expression statements are printing the values that were determined by the declaration statements.

Hello whoever is reading this! Hope you’re enjoying the course! Don’t copy my answers, I’m probably wrong :wink:

It brings in a library of pre-written code that we can access.

All C++ code needs a main function, as it tells the computer what to execute. By returning an integer of 0, at the end, it can quit the code safely without errors.

We are declaring values for A, B and C, then declaring new variables that are the sum and product of A, B and C. All variables are constant, which means they cannot be altered down the line.

Loads code from outside sources to be used in our program.

The main function is the part of the program that tells the system how to start the program off. The return statement is there to let you know that it did successfully run all the way to the end of the code without running into some kind of error.

The main statement is defining the initial level the player is on and also the maximum level you can reach. I also increments the level the customer is on up by one after successful completion of a level and prints out the final statement that the player sees upon completion of the final level.

The preprocessor directive imports a library of code for our program to use, such as std::cout and more. The main function is what the operating system calls on for instructions, and the return statement makes sure that the program ends with no errors. In our coding, we use expression statements to write to the terminal, or assign values to variables. Expression statements are expressions followed by a semi-colon. We also use declaration statements to declare variables, whether initialized or uninitialized. These expression and declaration statements are giving a greeting message in our game, and providing the program with values to work with, while displaying those values in the terminal as the sum and product of each other.

I feel expression statements is one of those things that are easy to understand but hard to explain, but I’ll give it my best shot. An expression statement is something that expresses/makes known a certain variable when the script is run. A declaration statement is more set in stone, quite literally declaring the value of certain variables for later use. The main() is there to actually make the code work with return 0; making it end. The preprosesser directive loads variables from another library, like loads the cin and court commands.

Preprocessor Directive - Includes code from another library containing code.

Main Function - Main function of the code, in this case, displayed to the terminal in our TripleX project. It contains the declaration statements and expression statements with math calculations for product and sum.

Declaration Statements - Code that declares something.

Expression Statements - one of the most common type of statements, a statement followed by semi-colons.

My main is wrong probably due to the fact I didn’t derive a proper definition in my doc.

What does our preprocessor directive do?

preprocessor directive
is the instruction to the complier
used to include a library before compiling

Why do we have a main function?
the main function is to start the program

What does it’s return statement do?
the return statement tells the program if there is a error after starting i.e if it doesn’t return with the value of 0 it will say error

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

expression we are stating that we want the program to print to the terminal

declaration is code that declares something. it is declaring our variables

What does our preprocessor directive do?

It calls the compiler not to compile before making some specific libraries available

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

Its the central structure of the program, the one that the computer executes first and where all other instruction routines branch from. Its where the code starts to be executed. The “return 0” is there because the OS expects an integer value for the end of the program, so we return 0 to signal the successful end of execution.

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

Expression: We used iostream libraries to output to screen some text related to the game.
Declaration: We declared values to variables after we initialized them. Initialize tells the compiler that a particular string is a variable and can be assigned a value. We also learn that we can declare that an assigned value will be constant so its unchangeable from there on.
We used the variables to do arithmetic operations.

By this point the program posts 2 frases and 2 values to screen.

preprocessor directive: is what bring in the complier form other source so you can use it there

main function: is what run the function form the preprocessor because the preprocessor have already identify it but but we cant use it without the main function

Expression statement: base on the name I think an expression statement is a statement that run after the main function that is just a statement

Declaration statement: is what give meaning to a variable or keep it secured form your self

return statement: is what return the value of and expression or return control

i dont know if these or right never take C++ or any coding before

Preprocessor directive: include libraries
Main function: the body of the program, where everything is executed.
Expression statements: instructions to do in the program.
Declaration statements: defnition of variables and initial values.
Return statement: finish the program.

What does our preprocessor directive do? Ans: it includes codes from other libraries before the code is compiled

The execution of all c++ programme begins with main function… without it the compliler won’t let the programme run… the return statement returns a 0 if all thing is running correctly

  1. we expressed some text which helps us to introduce the story of our triple x game

2.Initialized variables a,b,c,sum,product (store the addition of a,b,c in sum and multipication in product variable)

3.We add const to a,b,c variable to fix their values
4.Then we return 0…it will let the program know that everything is running correctly.

What does our preprocessor directive do?

Include references in an external C++ library that allows our code to do a certain task? iostream allows us to output to the console.

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

The main function is the main body of the code, required to initalise our code, return is used to end the process once completed.

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

Expression statements seem to be anything that isn’t declaring a value, they can later change a declared value but they cannot do that themselves. Right now they seem to be used purely to print to the console.

Declaration statments are used to set up values that may be required for use elsewhere.

What does our preprocessor directive do?

It loads other libraries or lines of code from an external file so they can be accessed in our code.

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

the main function is mandatory in C++ and it’s the function that runs the program, in it. We use the “return 0” to detect if there were any errors when the code was run. if there weren’t any, the program will return 0, otherwise it will return something else.

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

first we loaded iosteram which is an external library, then we declared the main function, in it, we declare some expressions to print out as text, then we declared the variables of the game, then we printed out some of it’s values and finally we closed the main function by returning 0 before closing it’s brackets.

At the code we find different type of statements that are written in different spaces of the script. The different locations and it’s syntax indicates it’s purpose and it’s functionality.

At first we find the include code. This lines links code that is written in other scripts and we can’t see explicitly on our code but can be used. In this code we link the iostream library that allow us to use different Input/Output methods. This include lines are called preprocessor directive because tells the linker functionality (a pre compiler functionality) which other scripts will be used at the code’s compilement.

main function, the starting function of any c++ application, starts with the next function syntax:

  • int -> returning value
  • main -> function’s name
  • () -> no params needed
  • { -> open bracket of the function’s code block
  • […] -> code written here

And ends with the next statements:

  • return 0 -> return statement that indicates a return value (value must be the same type of the returning value at the function’s signature. In this case 0.
  • } -> close bracket of the function’s code block

We find two type of statements inside the main code. In one side we find expression statements that executes logic operations and allow the application to execute multiple functionality, and int other side the declaration statements that creates spaces where values product of the expressions can be stored. Store a value can be considered an expression statement by itself. So the code do the next:

cout functionality, at the first lines of main function, executes output functionality written at iostream script, declared at the preprocessor directive. In this output function we explain to the user what’s happening at the game and let him know the situation.

The next lines we declare a, b, c, sum and product constants. Constants are value containers like variables but can’t be changed once defined. Constants values must be defined at it’s declaration. A declaration statement must contain the type of the value that a constant/variable is going to contain and the name that we are going to reference in the code.

The assignement of values to a variable or constant can be considered expression statements. So at these lines we are declaring constant but we doing some maths in order to assign this values to them.

The last lines are the output statments to the user of the constants we declared at the previous lines.