In simple terms a nested if is when you write an IF inside another IF braces.
This is the basic structure of a nested if.
if( boolean_expression 1) { // Executes when the boolean expression 1 is true if(boolean_expression 2) { // Executes when the boolean expression 2 is true } }
And of course we can nest else if in the similar way as you nest the if statement.
This is an example of a program with nested if-else.
#include <iostream> using namespace std; int main () { int marks = 55; if( marks >= 80) { cout << "U are 1st class !!"; } else { if( marks >= 60) { cout << "U are 2nd class !!"; } else { if( marks >= 40) { cout << "U are 3rd class !!"; } else { cout << "U are fail !!"; } } } return 0; }
And this will be the output:
U are 3rd class !!
-The Admin.
]]>I really had a great time with Ken as my teacher and his way of teaching is incredible! I had never been on a class where I feel like the teacher was actually my friend and he helped us a lot through our way in the course.
I highly recommend a flipped class room and even more if you have the opportunity to be with Ken Bauer, he is one of the best teachers that I ever had.
Thanks Ken!
-The admin, Esaú.
PS: Here is the video.
Euclids Algorithm:
The Euclidean algorithm is based on the principle that the greatest common divisor of two numbers does not change if the larger number is replaced by its difference with the smaller number. For example, 21 is the GCD of 252 and 105 (252 = 21 × 12 and 105 = 21 × 5), and the same number 21 is also the GCD of 105 and 147 = 252 − 105.
Here is the code of the program.
#include <iostream> using namespace std; int gcd(int a, int b){//Making the function int g=a; int h,l; int f=2; if(a==0){ return a; } while(g>0){//Doing a loop if(g==0){ goto exit; } g=a%b; a=b; b=g; } if (l=1000){ exit: g=a; } return g; } int main(){ int a, b; cout<<"Please introduce the first number"<<endl; cin>>a; cout<<"Please introduce the second number"<<endl; cin>>b; cout<<endl; cout<<"Your Greatest Common Divisor is: "<<gcd(a,b)<<endl; return 0; }
Also, Here is the link to the code in Github: BATMAN.
And of course, as always, the picture of the execution of the program on Cygwin.
-The Admin.
]]>
Well, the programs that I used were Atom to write the codes and Cygwin to compile them.
Also, I saw a tutorial from my teacher, Ken Bauer, who explains clearly the whole process of creating this little program.
I will let you the links of the video tutorial, the codes that you will need and of course I will tell you where you can download Atom and Cygwin completly free!
Here are the programs that you will need:
And Over here is the VideoTutorial!
Hello World C++ Video Tutorial by Ken Bauer
And, here is the link to the TLC101 hastag that will link you to all our twitter publications about this Programming Course.
PD:
Here are my own codes and the execution of the program in Cygwin and Clicking HERE you will find them on my GIthub Account!
]]>