Explain our code so far in Triple X!

What does our preprocessor directive do?

The preprocessor directive loads code from a library prior to our code’s compilation.

int main(), return 0;

This code is used to compile and check for errors, respectively. Without int main(), the code wouldn’t compile. Without return 0;, we wouldn’t have a way to check for errors after runtime.

What is our code doing?
  1. We expressed information through text
  2. We declared initial values for our variables, along with their sum and product
  3. We then expressed the values of sum and product
  4. Finally, we returned 0 to check for runtime errors

The pre-processor directive tells the compiler to include the iostream library so that we have access to the std::cout functionality for printing to the terminal screen. This code needs to be included into the code before the code we have written is compiled.

We have a main function because this is the entry point to the program. The C++ compiler will not allow a program to be compiled without it. When the program is loaded, this is where execution starts.
The main function is an int function, meaning that it returns a value at the end of execution. This is a status code that is returned to the operating system (0 meaning completed successfully)

Our expression statements print data out to the screen. (Specifically, the first block of expressions introduce our game to the player and what task is to be completed. The second block prints the result of arithmetic operations as stored in our declared variables.)

Our declaration statements set up a series of int variables which store values that are constants.

What does our preprocessor directive do?

It instructs the compiler to load a library. In this case the iostream library, which should stand for input output stream.

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

To instruct the compiler from which function it should start execute the software. The return statement indicates if the software was execute successfully (0), or not (any other value)

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

Expressions statements are any statement that assign value either to a variable or to a function.
Declaration statements, are statements that define the type of a variable. Thus, we’re preparing three numbers, their sum, their product, and printing said sum and product, returning a successful response.

The preprocessor directive includes a bunch of someone else’s code into yours, making statements that are foriegn in pure C++ usable. The main function can be recalled in a mere single line of code which, in turn, activates a bunch more lines of code. Expression statements are expressions with semicolons at the end and decloration statements declare a value to variables, constants etc. Lastly, the return statement gives back a value that the code which is calling the function can use.

1 Like

THe preprocessor directive tells the compiler to access that source code before using any of the code we are writing ourselves.

We have a main function because it is what our entire game is based around. The return statement simply ends the code.

Our expression statements are the statements we are using that end with ; and our declarations statements are the statements in which we are declaring a value to the variables.

Preprocessor directive: tells comipler to add the code of our included header iostream
Main function: We need main function in all our codes because it the main function that we r telling compiler to execute
Return statement : our main function is int type so we have return statement return an int value at the end of our function

Expression statements : They are printing out stuff to output screen
Declaration statements : Declaring different variables that we are using in our code

Preprocessor Directives make calls to other libraries so we can re-use code instead of reinventing the wheel each time.

Main is what is looked for by the OS in order to run the program. The return statement is what is returned to the compiler when the program is finished.

We declared integers named difficulty and maxDifficulty.
The while loop will run until difficulty is at most 10 then it will exit the loop.

If there are no errors, main returns a 0.

It allows the program to incorporate libraries that have been pre-created to allow for easier usage and greater functionality.

The Main Function is where the computer starts executing the code, following the instructions step by step. For the function to complete properly, it needs to output an integer. Return 0 at the end of the function tells the computer that the function has completed and gives the function an integer of 0.

An expression statement allows the computer to give information to the user, while a declaration statement lets the computer initialize and set information without having to give that information to the user.

What does our preprocessor directive do?

Loads up code from another source or library

Why do we have the main function? What does it returns statement do?

the main function is the actual code that it will compile
The return statement is there to show that the program has run successfully.

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

The expressions are providing visual information to the player, the declaration are explaining the values that can be used in the expression statements.

Hello everyone! I’m excited to get started :slight_smile:

Preprocessor Directive: Tells the compiler to grab and compile an external library of code before compiling our code.

The main function is the entry point for C++ programs, and sought out by the OS. Without it, our code can’t be compiled.

Return: Returns a value to the OS.

Expressions that end in ; are Expression Statements, whereas Declaration Statements declare something.

Currently, our code uses Expression Statements to tell the player a bit about the game and to send outputs to the console. Our Declaration Statements are declaring the variables.

To Review!

A preprocessor Directive gives an order to the compiler. The include statement used in our code so far includes the input and output stream library that allows us to use cout and endl.

Our main function is the where the processor looks first to start executing our code. It is the starting point! Its return statement tells the processor that the code has properly finished executing.

Expression statements express something and are followed by a semicolon. Our expression statements send output to our terminal that includes the sum and product of our three variables.

Declaration statements are where we declare variables and initialize them, this includes the creation of our a,b, and c variables and their value assignments.

Our program overall outputs some text which delivers the intent of the game to the player, creates some variables, and outputs a few of the variables to the console.

The preprocessor directive loads codes from another library before it complies.

Every program needs the main function or otherwise it won’t run. Return statement is used to see if there is any error, that is, if it returns zero everything is fine and if it returns anything else it means that there is a error.

First we expressed (or printed) two lines of string, then we declared several variables and its values. Afterwards we expressed (or printed) the values of two of the variables we declared previously. Finally it returned zero to state that the program executed successfully.

Give us opportunity to uses code that someone else has created, so we dont have to write that much line of code. It give us many functions written by others (depending on library)

Every program must have int main() functions, otherwise it will not run.
The return statement chech if there were any error. If there was no errors it returns 0, otherwise if there were error it returns anything but 0.

  1. We write few lines of text
  2. We declared int (integer) a, b, c.
  3. Expressing the values of sum and product.
  4. Returned 0 to chech if there were any errors.

What does our preprocessor directive do?

The preprocessor directive loads code from another library (a collection of code written by other programmers) for us to use in our own code, before it is compiled.

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

The main function indicates the start of our code and allows it to run on the OS. Without the main function, the programme wouldn’t run. The return statement specifies whether the programme executed correctly - in this case any value other than 0 would indicate an error.

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

  1. First we declared two lines of text for the story of TripleX.
  2. We then declared the variables a, b, c, sum and product.
  3. We then expressed the values of sum and product.
  4. In the end we returned a 0 to check for any errors.

What does our preprocessor directive do?

It accesses an existing library of code for us to use in our code.

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

The main function initializes the code. It is our starting point, and the main function. The return statement ensures the main function returns without error.

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

  1. We expressed two lines of text.
  2. We declared and initialized variables a, b, c, sum and product.
  3. The values of sum and product are expressed.
  4. Return of zero checks the code for errors.

My thoughts:
Preprocessor directive is what is done before compiling
Expression and declaration statemens speaks for themselfs, expression is how you express your code (what and how it does things) declaration is what you use to express your code.
Return statmens returns an end result of declarations and expressions.
Main function is the ignition of written program
In our code we expressed what the game is about and gave some feedback, and declared our secrets which player will have to guess eventually.

The preprocessor statement is cut and pasting whatever the upstream has in its file.
The main function is what tells the compiler where to start for the program.
The declaration states ware what telling the computer what we want it to do. In our case is is telling it to print out these statements.
The expression statements are expressing that that the values are assigned to it.
The return statement is what signals that the function is complete.

The preprocessor directive: Calls in a library of code called Iostream so that we can use expression statements related to it.

The main Functions allows us to define the part of the code that is running versus preprocessor directives.

The expression statements allow us to print lines of text for the user.

And the Declaration statements allow us to define variables to be called.

  • The preprocessor directive goes to a header file and includes it into our code.

  • The main function is initializing the code, and it is also where everything gets run.

  • The expression statements are outputting to the console.

  • The declaration statements declare our variables.

  • And the return statement exits our program.

The preprocessor directive "#include " is including code that allows us to print to the console. The main function is called by the OS to start our program and the “return” at the end of the function ends our program and returns a value back to the OS. The first set of expression statements, print out an intro message to the console. The declaration statements declare and initialize our pass code, sum and product variables, needed for the game. The second set of expression statements, print out the sum and product to the console.

1 Like

Privacy & Terms