Author Archives: Juan Carlos

#Mastery16

16 1017

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 10)

{

     cout

} else {

       cout

}”

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

17 1017

Here I am presentig you the 17 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!

https://www.youtube.com/watch?v=o32Y5ZBN7zM

#Mastery15

1017 15

Hello i am doing my 15 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 10) //This is the condition

{

     cout

}

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.

28 1017

https://www.youtube.com/watch?v=PW9OYXnIBS0

#Mastery07

07 07 1017

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

01  01

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:

     1.- Open your editor (notepad, notepad++, sublime, jeditor, etc..).

     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 , ) 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.

#WSQ17

17 17 1017

In this WSQ all we have to do it was download Scilab and play with it. So I did.

At first i didn´t have an idea of which use does Scilab had or what was the point of using it.

But i started reading the instructions and turns out it was a really fun program. I play by doing math and  some conditionals.

I really liked it, in the courses that i´m right now i am not shure if it would help a lot but i´m pretty sure that later in my career it would. In courses like math, elecricity, physics and other ones I´m shure it will be really helpful.

I wouls like to use this post to say thanks to my profesor Ken Bauer who i can honestly say  is one of the best teachers i ever had, becuase of his way of teaching which is Flipped Learning who makes you learn by yourself and be independent from your teachers, or just contact them when you really need them.

Just to make an example. This wsq isn´t really about c++ but is tool which can be really useful for some of us and Ken wants us to know how to use because of that.

Thanks for everything!

#mastery12

12  12 1017

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

11 11 1017

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

10 10

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 ”

An example to output text you will put upper commas:

cout

An example to output a function you will do this:

cout

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

cout

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

cout

Here is everything together:

cout

——————————————————————————————————————————————–

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!