Explain our code so far in Triple X!

What does our preprocessor directive do?

The preprocessor directive imports code into this C++ file. The compiler includes these files as part of the code that is run.

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

The main function is included as the main() function is called first in any C++ file. The return statement ends the program.

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

The expression statements are creating our outputs and the the declaration statements are initializing our variables.

What does our preprocessor directive do?

It loads a c++ library, in this case iostream is the standard c++ library.

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

It is a special function in all c++ programs, as it is called when the program is run.

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

  1. Expression statements to be printed in the terminal, they indicate a purpose for the program
  2. Declaration statements to declare variables
  3. Expression statements which return the operations performed by the variables we declared
  4. Return statement to end program.

What does our preprocessor directive do?

The preprocessor directive tells the compiler to include the named files in the code. It copies the code included in that file so that it can be used by the code we are writing.

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

The main function initializes the program. Without it, the compiler will not compile at all. The return statement tells the program whether it was successfully run or not; if it passes a 0, it means it was a success.

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

The first expression statement creates a storyline for the player by printing a narrative in the terminal. It does so over the course of two lines by using std::cout << std:endl;.
The declaration statements that follow initialize the variables we will be using for our code, and make them constant so they cannot be changed later. They also add and multiply the variables together.
Finally, the expression statements that close out the main body before the return statement output the results of our addition and multiplication to the terminal on two separate lines.

My only question is: if expression statements are defined by the semicolon at the end, does that mean that declaration statements are a subset of expression statements since they end in a semicolon?

Preprocessor Directive

This will load another library of code created beforehand.

Main Function

Is the start-up for a program. without the main() the program won’t run.

Declaration Statement

These statements declare values to variables and can signify if the variable is constant and meant to be unchanged in later updates to our code or left to be modified at a later time. I suspect this attributes the game to either have answers that have the same outcome or change as each task is accomplished and the game progresses to an end state.

Expression Statements

Lines of code meant to attribute a program with a form of expression such as a printed line of code or assigning a value to a variable. This allows us to output a message and said variable with its attributed value in the terminal once compiled and run. Also the ; at the end signifies these expressions as statements. I gather this process allows us to express our desired outputs once the code runs during the game’s progress stages.

Return Statement

Return 0 ensures us that the program code has compiled and ran without error. If the operating system does not receive the zero once the code has been run the system will show us an error that can be fixed.

Preprocessor directive is the way we have to declare a library, that is, code written by another to make work easier for current programmers.

Main Function executes all the code written by ourselves.

Declaration declarations are the values ​​we will use to arrive at the results we want.

Expression declarations executes methods.

Return statement allows you to correctly execute Main Function. If it returns 0, it has no errors, but if it returns any other value then it is an error

I don’t know if I got this right but here goes nothing!

“what does our preprocessor directive do?”

It grabs bits of code from another library to input in our own code.

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

The main function is the core part for running the code; without it, the code will not run.

“Explain expression and declaration statements”

Expression: We expressed text to be displayed in our code
Declaration: We declared the variables with their (set) values.
When the code is being compiled and run, it will show the outcome of the expression and the declaration.

Well, the initial part “#include <iostream>” is a directive for compiler to include a set of predefined functions into this particular code that we expect to use later.
Then with int main() comes the definition of a main function every c++ compiler is looking for as a start and a main body of functionality of particular code.
Within the mentioned above main function the first set of expression statements is used for communicating to user the story and a problem itself.
Next comes the set of variable declaration and initialization. In this case as constants since the values are not supposed to change afterwards.
The second expression statements are the ones that through the terminal communicate the user the values of sum and product of the previously defined constants.
And finally, as everything passes without error, the return statement returns ‘0’ as a result of main() function indicating for the system that program ran as it should.

  1. #include” is used to include a library before compiling. cout and cin is a
    part of iostream library which we added by using #include.
  2. main() function is the entry point of our c++ program. Wtihout it our program will not
    build.
  3. statements like:-
    std::cout << “hello world”; & a = 4;
    are Expression statements.
    statements like:-
    const int a = 4; or const int b = 5;
    are declaration statements.
  4. return 0 is to signal our program has run successfully.

Preprocessor directive: these are instructions that go to the compiler to convert the code we’ve written into binary code that the computer can read.

Main function: This is the entry point for our program. Any code we write is outputted from here.

Return statement: this is our error detector. If the code is read and there are no errors it will return zero and run our code. But if there is an error it will show up in our compiler.

Expression Statements: these statements are what we want to show in our game. anything within a std:: will be pushed to the terminal.

Declaration statements: these hold our variables that can be called back to with the variable: only if it is underneath the declared integer.

Summary: So far our program is taking orders to our compiler to convert our code into machine binary. then it is loading our main function which houses our code. This brings us to our expression statements which is the main dialog of our game. Now we have the declaration of our variable in our games which is the code our player must figure out. That brings us to our next expression statement and that is the sum and product of our chosen code. After that is checked our return statement looks for any errors and send the saved code to the compiler to be converted.

Lastly we simply run our code through the command prompt with typing: triplex

If there’s anything I’ve misunderstood please correct me and let me know if i left something out.

Thanks and good luck!
Reece

What does our preprocessor directive do?
Preprocessor Directive is a library which is a function or a class.That is coded by other programmers just to make the data from the library use it to for our uses.
Why do we have a main function? What does it’s return statement do?
We have an int main() function to run our code and also return statement allows us to check the code if there was an error

Preprocessor Directive - any dependant code required for the program.
Main function - the main body container for written code for the program.
Expression statement - any piece of info we want to ‘express,’ or show to the user.
Declaration statement - declaring values of variables.
Return statement - requires program to check for errors, and return ‘0’ errors to run successfully.

The preprocessor directive is something that processes before your code compiles.
The main() function is where the program starts.
The expression statements are expressions followed by a semicolon.
The declaration statements are where things are declared.
The return statement is where it checks to see if the program ran successfully.

Starting from the top,
1.# include is a preprocessor directive which by name itself suggests that it directs the compiler to include the file which follows after it, iostream in our case.And its syntax is #include <filename> without semicolon.

  1. int main() is the must include function in a C++ program as it is the function which is called at first by our system while running the program.

  2. Expression statements are simply the expressions ending with a semicolon like cout statements.

  3. Declaration statements declares something like declaring a variable in our code like int a=4.

  4. As we see that return type of main() function is int so we return 0 to the system which means successful execution, non-zero return suggests errors.

the #include preprocessor directive tells the compiler to include a portion of code made by us or someone else that we don’t get to see, the compiler just knows it’s there. The main function is the function that the compiler runs first by default, the main function can call other functions to do other things. The return value is sending a value that tells the compiler what happened during the program, if the compiler receives a 0, the program executed without errors, if it receives a number other than 0, there was some type of error that happened

What does our preprocessor directive do? The preprocessor directive loads in a code library with methods in namespaces that gives the IDE its functionaility
Why do we have a main function? What does it’s return statement do?
The main function is mandatory, without it the code wouldn’t even compile. It is the first function called upon and has the majority code nested within it. The return function returns a 0 if there were no errors, otherwise an error is detected.

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

The expression statements do not include declaring variables. They are simply like placeholders for text or a variable.

std:: << “Hello World”
Declaration is where we first declare then initialize a variable by giving it a value and nameholder.

int a = 40;

The return statement returns a 0 (Which means nothing in computer language) if the code runs, otherwise an error is spotted.

What does our preprocessor directive do?

  • The preprocessor directive basically adds in a library that functions as instruction to the compiler.

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

  • The main function is a must have function, otherwise the program wouldn’t even compile! And its return value is used as an exit status to the operating system.

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

  • The expression statements we’ve written so far are outputting both text and variable values.
    While in the declaration statement we’ve declared and initialized our variables.

it give information to compiler to bring programme from another library before to compilation #include

main function is like blood in our heart like in our body we cant move with blood like that int main() is nessary to start the programme for basics.
return 0; is function that provides info to users whether the work is success or failure

  1. we started with are apreciation of the player playing the game and explain him the rules of game
  2. then we start to give value to abc and sum and multipliction the value and declared and intialized
    3.in terminal window we found the sum and product of our output and get desired result
  3. then i got 0 retur theat means we are sucess
  4. now celebrate with drinks

The preprocessor directive calls the header file or the library of codes that we’re going to need to run the program. The main function is essential because it signals the start of the program, without it the program will not run. The return statement signals that the program has run successfully.

We have expression statements that tells the program what to print on the screen (std::cout) and where to end it (std::endl). But expression statements that declare a variable are called declaration statements.

Overall, the few things that the current program can only do is to compute and print.

:relaxed:

  1. Preprocessor Directive:
    It is the first line of code where we include a c++ library known as iostream.
  2. Main Function:
    Here we create a function which is the main function under which all program gets executed. When we call for the main Function all the code gets executed inside that function.
  3. Expression statement:
    These are the statements that gets executed depending on the command given to be followed.
  4. Declaration statement:
    Here we declare variable, constants and provide variables with values.
  5. Return statement:
    Not sure about it but well all i know about it is that it returns the value and acts as last statement to be executed because it stops the function from executing any statement further more and returns the value there and then.

Feel free to correct me at any point. I’m very new to all this.

The preprocessor directive uses code that other people have written, such as cout.

The main function is the entry point for a c++ program.

Expression statements are an expression that end with a semicolon.

Declaration statements are statements that declare a variable.

The return statement returns the type of variable indicated by the function (in this case int).

Let me know if I missed anything :slight_smile:

Privacy & Terms