# Juan Carlos

Student at TC1017 with Ken Bauer

## #Mastery16

This is the second time I do this Mastery16 in order to make  two points out of it!

I will explain you how to use an else conditional..

But first, why use an else conditional and how does it work. Well the else conditonal  is use with the if conditional which i already explained earlier. The else conditional is when the if conditional is false, lets say, if you ask the user something with if and is true  it wil return you whatever you put there, but if it isn´t true then it will not print anyting unless you have another if or somekind of cout outside the if, but is more bother to do that.

What the else conditonal does is  to return you something if the if conditional isn´t true.

The syntax for using else is:

"else

{

}"

As you can se is pretty easy to do so sure it will be no problem using it.

But let see how will you use with an if when the variable num is somehting the user give us and we ask for a number between 1 and 10:

"if (num < 1 || num > 10)

{

cout << "Your number is invalid" <<endl;

} else {

cout << "Great you put a number between 1 and 10" <<endl;

}"

What does it say with words "If you put a number less than 1 or higher than 10 then it prints "Your number is invalid", or if your numbers is higher or equal to 1 and less or equal to 10 then it prints "Great your number is between 1 and 10".

So here you can se how easy is to use the else conditional and that it is very very useful when your are doing enourmous codes and your tired of writing or just because is not compplicated.

Hope you learn from this!

## #Mastery17

Here I am presentig you the which explains you how to use  a switch as a conditional.

I made  a video in youtube for you to understand it better, hope you enjoy!

## #Mastery15

Hello i am doing my al over again because i want to get my two points!

I will be teaching you how to use a conditional if.

First of all lets see why conditionals are useful.

For me personally, the use of conditionals is  one of the most important things in c++ programming or in any kind of language or algorithm. Because is such an easy way  to do things, or to lead the user where he wants to go.

An if or conditional, is to give the user an option if he wants something or no, or also if the user put something he can´t the program will say no, because you said tha IF he put that it will say no.

But, lets do an example for you to understand it better.

the syntax for using an if is very easy:

"if (conditional)

{

}"

Yes, is that simple.

But let say you ask the user for a number between 1 and  10 and the name of the variable that the user will give us is "num".

if (num < 1 || num > 10) //This is the condition

{

cout << "Your number is invalid."  <<endl; //This is what the if will do if the conditon is true

}

So what did i did here. In words this tell "If the number the user gives is less than 1 or more than 10, then print (Your number is invalid).

As you can se is very simple and you cant put various times or combine it with for loops, while loops or whatever you want.

Hope you learn from this!

## #Mastery28

Hey everyone, in this post i will be explaining how to import or write in files on c++.

Cause is a tricky explanation i made a video in youtube so i hope you enjoy it.

PS. this was one of the most dificult things for me to learn, so i hope it will help you.

## #Mastery07

Hi!

I am doing this mastery all over again because i wan to reach to 2 points.

I am teaching you how to put comments in c++.

Well first of all lets talk about why to use comments in codes?

The answer is really simple, because sometimes you are making a code with other teammate or something like in the final project of Sudoku were you ra syncing with github, maybe the other guy modify somehting and you dont know what he had done so he put  a commento to et you know what does it mean.

Even if you´re alone the comments  will be useful when you want to try your program without a function or something but you are scared of deleting it, just put it as a comment an the problem is solved. Or when you don´t want to forget what you did or even when you are uploading to github, put a comment to let Ken know what is your doubt or what you´ve been doing.

With that said, lets see how does a comment is made.

There ar to kinds of comments

The first one is just by putting two slashes befor you write "//", the perk of this comment is that you can only use it in one line.

The second one is to put slash and asterisc at the beginning "/*" and then asterisc and slash at the end "*/", the good thing with this one is that you can use it in as many lines as you want.

Hope that this post is useful, enjoy it.

## #Mastery01 #MASTERY01

I am doing this mastery again because i want to get the two points.

Well in this one I want to teach how to create and run a c++ from command line.

Im going to give you a couple of steps to make it easier to you to understand it:

2.- Save your program as a c++ file and in the end of the name add ".cpp" so the terminal will run it.

3.- Start coding.

3.1.- Include your libraries, ALWAYS include (#include <iostream>, <cstdlib>) the cstdlib is not always             necessary but add it anyway.

3.2.- Before everything put "usingnamespace std;" so you don´t have to put it all over your code.

3.3.- You will always have a "int main()" it doesn´t matter if you have functions or not.

3.4.- ALWAYS at the end of the "int main()" put " return 0;" is not really necesary eaither but every programmer             will tell you to put it.

4.- Open your ternimal (cygwin, mac, linux, etc..) wait until it recognize your computer and then put "cd" to change        directory then put "/" to go were ever is your code you made in your editor.

5.- Finally after it compiles you have to execute it with "./a.exe" in wondows, "./a.out" on Mac an Linux.

Hope you understand and learn from it.

## #MASTERY12 #Mastery12

I´m goint to teach how to create a function in c++

First of all you have to choose which type of function you want.

Void = to return nothing.

Int = to return a integer number.

double = to return a decimal number.

bool = to return true or false

string = to return letters.

etc etc.

Well now that you know the types of functions you will have to select the  type you want for your variables which are pretty much the same.

Now, the syntax to do a function is:

type nameoffunction(variables, parameters)

{

}

--------------------------------------------

Let´s say, we want to create a function which make the sum of two integer numbers

int sumnum(int x, int y)

{

int c;

c = x + y;

return c;

}

Hope you understand how to create a function, it is really easy and don´t be afraid to create them because it will save a lot of coding and your int main() will be a lot shorter.

Hope you understand so i can get my two points!

## #MASTERY11 #Mastery11

Here i will teach you how to call functions in c++.

First of all you will have to create a function and put parameters in it. And put what kind it is, if it´s int, bool, void etc..

To call it you will go to your int main and write the name of your function. Here is an example.

int function (int a,int b)

{

int c;

c = a + b;

return c;

}

int main()

{

function();

}

So you basically just put the function number and "()" or if it has parameters "(parameters)".

Hope you understand so i can have my two points!

## #Mastery10 #MASTERY10

Here i will explain you how to do basic output and input text based in C++.

To output something is really simple. in every output you always will have to put "<<" after you put cout. and a semi colon when you finish.

An example to output text you will put upper commas:

cout << "Heres you put your text" ;

An example to output a function you will do this:

cout << function(parameters) ;

If you want to put some text and a function is:

cout<< "Heres is my function << function(x,y);

If you want to put end the line after whatever you print put this.

cout << endl;

Here is everything together:

cout << "Here is my function" << funtion (x,y) << "an end line" << endl;

--------------------------------------------------------------------------------------------------------------------------------------------

To input something the first thing you want to do is to declare the variable were you want to save the input.

If is an int variable just put   int n1;

If is a string  name; (You will have to include the string library)

If is a boolean  bool n1;

And etc.

After you now this the syntax to an input is:

cin >> ;

Let´s say you will save a number which is variable is n1.

cin >> n1;

That is basically everything to know about input and output in c++.

Hope you understand so i can  get my 2 points!

## #mastery04 #MASTERY04

This mastery is to demsotrate how to upload work via Github but i will teach you how to do it.

1.-To begin with is you have to create a Github account which a supose you already have if your in Ken´s class.

3.- After you download it  go to the plus symbol "+" and click on clone.

4.- Now go to the web into your account and create a repository with any name you want.

5.- Now return to app and insert the url of the repository you created.

6.- After that choose a carpet in your documents were you have your codes (I suggest you to put your carpet and your repository the same name).

7.- Click sync so it will sync with your carpet.

8.- Click were it  says, commits and do the commit or the change.

9.- Click sync again so it will upload to your repository in the web.

That is if you want to upload a file having the github app. In case your app doesn´t work or you don´t have it, go to the web, click on your repository and were it says "branchmaster" and your repositoriy´s name, is a plus symbol "+". Click there and select the file you want to sumbit.

I hope you understand so i can get my two points in this mastery!