Explain our code so far in Triple X!

<iostream> is a header file which contains codes.

#include is a preprocessor directive.

int main() is the entry point of c++ and without it the program wont run in c++.

Expression statements are used to tell us the objective to the game.

Declaration statements are used to declare things in the game.

The return statement is used as an exit status to the operating signal.

#include <iostream>

We are asking the compiler to recognize and call into action the codes associated with iostream so allow the program to run after being compiled. It’s like a library of codes that we include in every C++ program so that the functions we create later can run.

int main()

We are calling a function here. In order for the program to work, you must call the function, which will work with integers.

    std::cout << "You're on a secret mission, and you encounter a terminal";
    std::cout << std::endl;
    std::cout << "You need to enter the correct code to enter the next room...";

We are telling the terminal what to output. The terminal is what the player/user will see once we run the game. This is what gets output in the terminal after the code gets executed.

    const int a = 4;
    const int b = 3;
    const int c = 2;

    const int sum = a + b + c;
    const int product = a * b * c;

Since our game is based on guessing numbers, we need to be able to tell the system what to do when numbers are input by the users. In this case, the user has no input option, and instead we are stating what numbers should be used in the code. By using ‘const’, we are saying that we do not want the values of these integer based variables to change.

    std::cout << std::endl;
    std::cout << sum << std::endl;    
    std::cout << product << std::endl;

After we declare our constant variables and assign values to them, we can use various operators to create sums, products, or dividends. Basically, this section is saying we will make a new line after each operator is executed. So for example, if we add the variables that were declared, the terminal will output the correct integer and put the terminal cursor at a new line beneath so that more output can be given.

    return 0;

We are saying that once all the above code in the program runs, to stop the program from running again.

Preprocessor Directives loads code from another library, to basically make the C++ run.

int main ()

It allows us to define where our main function is located.

return 0

The return statement is there to exit the program without any errors.

Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.
  • Firstly, we have printed some lines to start our own story for the Triple X Game.

  • We then declared variables, namely “a” , “b”, “c” and assigned them some integers.

  • Then we have performed some arithmetic operations using + , - , * / operators.

  • And finally we end our code with return 0 .

This tells the machine to load in some library of code before we do anything else.

We need a main function for our C++ to run, and its return statement is what lets the machine know we have successfully(or unsuccessfully) run the program.

An expression statement, expresses. Whereas, a declaration statement, declares something new.

  1. In this case the preprocessor directive lets the compiler know that it will need to call on and compile with the iostream library included before compiling any of the other code.

  2. The main function is needed for any c++ program to run. As the name implies this is the main function of the program. The return statement will only return a number if everything else in the main statement has been able to run. Returning 0 to int main() allows the program to know that it is finished. If 0 is not able to be returned it means that the whole program was not able to run before creating an error.

  3. Our first block of expression statements print out the story line for our game to the player in the terminal. The first block of declaration statements initialize the variables a, b, and c to be the numbers needed to break the code. The second block of constant variables will be the clues given to the player to help them solve the code. The final block of expression statements print out the values of the sum and product variables.

Our preprocessor directive includes a library of external code for use within our program.

The main function runs the program and returns 0 to indicate the program has run correctly.

Our first set of expression statements prompts the user with context about the program.

The declaration statements define variables and set their values for use within our program.

The second group of expression statements output the values of those variables to the terminal for the user to see.

Preprocessor directive
Includes code from other libraries that we access in our program.

Main function
Is the starting point to the program. When our application is executed, main is the first function run.

Declaration Statements
Is where variables and objects are declared to be used in our code.

Expression Statements
The logic to the program, we’re expressing what we want to computer to do

Return Statement
Telling the computer that we’re at the end of the function and return to processing the rest of the logic to our program.

#Include - I believe this includes other peoples code to make our game work somehow.

Int main() - This is main function of our code, anything after this is the core part of our code.

std::cout << “You a mage trying to get out of a dungeon…”;
std::cout << std::endl;
std::cout << “You need to enter the correct sequence of numbered runes to exit…”;

What this section of code is doing in terms of gameplay is printing letters to the terminal for the user to see. Also to add a bit of story to the game.

const int a = 4;
const int b = 5;
const int c = 8;

const int sum = a + b + c;
const int product = a * b * c;

This part of the code would be our actually gameplay, well in terms of text based games. This what makes the game work for the user to be able to play.

std::cout << std::endl;
std::cout << sum << std::endl;
std::cout << product << std::endl;

This part of the code is making sure that the user can read it more clearly and making sure not all the text is on one line. Also to print the sum and the product on the screen.

return 0;

This is telling the system to start from the first line of code for the next user that will play.

A preprocessor directive copies the code/library written by other people into our code before it being used. Without a preprocessor directive preloaded into the code, we will not be able to use the functionalities in the library.

The main ( ) is an essential part of every c++ code. The compiler will always look for this function during compilation, and throw error if this function is not present in the code. If we use “int main ( )”, the function returns an integer value using the “rerun” statement. “return 0” means the execution of the program is successful without any error.

An expression statement an expression with a semicolon at the end. It does not declare something but performs something like printing a string into the console or an assignment operation (Eg: std::cout << “Hello World!”;). A declaration statement declares a variable or a constant (Eg: const int a = 1;)

Preprocessor Directive includes libraries of code into our own.

Main Function is the most important part of our code. Without it, it doesn’t work. It is the entry point of our program.

Return Statement ends the execution of our function and can return a value to the calling one.

The expression and declaration statements, so far, show some text to the user, declarates three variables, sums it and multiply them in this sequence. Then, display the results of the sum and product of the declared variables.

The preprocessor directive tells the compiler to include a library before compiling to access its features in our code.

The main function is the entry point of our program when it runs, the code within is then executed. The return statement makes the main() function return this value when its done, it is an ‘int’ function so this is why it’s a number.

Our expression statements are there to print information to the terminal, and our declaration statements are there to assign values to our variables that can then be used in expression statements.

This is a pretty hard one for me to grasp.
But the processor directive seems to be, at this point in the lesson, an empty database of some sort.

The main function I think is to start running our code itself and the return is what closes it.

The expressive statements so far are just for plain text and the declaration statement I think is what does the actual computing so to speak.

Q:What does our preprocessor directive do?
A: Its will load any libary of code we need before we even start to code our own

Q:Why do we have a main function? What does it’s return statement do?
A:We need the main function becouse this function is telling the compiler in wich order
to compile the code so we can run the code in right order

The main function is waiting a int result to tell if we have any problem
if we got to return 0 we good and code run well

Q:Explain our expression and declaration statement that we have written so far, to summarise what our program is doing.
A:the first expression statment is the get the user into our story
while the declartion statment follwing it we are going to use in our code

Preprocessor directive, or the #include, basically adds a pre-written code library called iostream. This library is what we use and/or build on to write our own code.

The main function defines your main program, and is what the compiler looks for to run the program you’ve written. The return statement is a statement used to terminate the program without any errors, by telling VC to return a 0 once the program has run without any issues.

I’m a little confused here to be honest. I think I understand that any statement is essentially a line of code that ends wtih the semi-colon. But I’m not sure I fully understand the difference between expressions and declerations. A decleration is when you initialize a value I think, but then when you change that value why is that considered a decleration?

To summarize the program, we’ve first expressed our intention to show a series of strings, as well as blank lines, between them on the terminal. we’ve declared that our integers a b and c are going to be the values we’ve assigned to them, as well as declared what the integers sum and product will be. Then we expressed our intent to return the sum and product integers on the terminal. After that we’ve asked for VC to return a 0, in other words ending the program, once the process has run through correctly.

I really hope I’ve got that last part right hahaha. If anyone wants to correct me please let me know! I don’t know if the terms expressing or declaring are appropriate terms to describe what we’re doing.

I think main function basically is a starter code of our main code it basically tells us that we can now start our coding… while #include is a header file and acts as a library for all of our functions. Return statement returns us the value of our particular code or its end result… expression statement tells the compiler that the user wants to desplay or express the particular value in the system… declaration statement helps in declaring value to variables or constants…

The main () function is needed for our code to start. The return statement is needed for our code to successfully finish. The preprocessor drive collects coding directories from a different file that aids in compiling your code. Declaration statements declare a value in code. Expression statements print out strings and variables on the terminal in whatever viable format the programmer chooses.

A Preprocessor directive tells the compiler to include source code in the program.
A main function is required for any C++ program to run.
Our expression statement is a line that ends with semicolon, and a declaration statement is when we declare and initialize a variable.
Return statement lets the program close properly.

I am not quite sure of the difference between an expression and a declaration statement, since in the example in the video showed a declaration statement as an expression statement.

Preprocessor directive - An instruction to the compiler to include a library of code - written by someone else - before compiling the rest of our code.

Main function – The main function is required in every c++ program, when executing a c++ program your operating system will look for this function as a starting point. Without it the program will be unable to build.

Expression statement – These are used to tell the compiler what to print onto the terminal. We can use this to output variables in the declaration statements.

  1. In our program the first set of expression statements is printing a set of strings used to establish the scenario and introduce the task/conditions that need to be fulfilled in order to advance the game.
  2. Our second set of expression statements print the sum and product of our variables established in the declaration statement

Declaration statements – Used to declare variables, these variables are used to store date. By declaring a variable we are reserving a space in the computers memory.

  1. We are first declaring the 3 values that form the basis of our puzzle
  2. then we declare the sum and product of these 3 values
  3. Also our values have been declared as constants so they cannot be changed further down the line

Return – return value is used to signal the successful operation of the program, the operating system uses this as a exit status to end the program.

The Preprocessor Directive is include code from other sources that aren’t in our own code. The Main Function is the start of the code and is the reason the code will compile and run. The expression statements are bits of code that communicate with the user and give output or take in inputs. The declaration statements are bits of code that are use to declare or establish the values in code. Example being variables.

What does our preprocessor directive do?
This brings code form another library over to yours prior to being compiled.

Why do we have a main function?
This is needed in every program in order for it to run.

What does it’s return statement do?
This will check for errors. In our case if it returns “0” after the compilation, there were no errors. Any other value and something is wrong.

Explain our expression and declaration statement that we have written so far, to summarize what our program is doing.
Expression statements are the statements that are displayed after compilation. These must end with a semi-colon in order to work.
Declaration statements declare and assign a value to a variable. For our code we declared the “a” variable to have a value of 4.

Privacy & Terms